When you use Webmock or VCR or both together along with Cucumber, you will face an issue with your tests not being able to record as webmock and vcr blocks all outbound HTTP requests.
You will see error somewhat like this:
__identify__ path so it knows when it has finished booting.
There are few ways to tackle this problem based on your situation
1. If you are only using only Webmock
If you don’t need it, remove it from the Gemfile. If you do need it, then you may need to configure it more precisely to your needs, one thing worked for me is adding this snippet to my env.rb
By doing so, you allow real web access to your localhost.
2. If you are using vcr & webmock both
If you’re using VCR, you don’t need to configure webmock with the
require 'webmock/cucumber' line and the
WebMock.allow_net_connect! line. VCR takes care of any necessary WebMock configuration for you.
VCR includes support for ignoring localhost requests so that it won’t interfere with this. The relish docs, but in short you can use this snippet in VCR configuration to get it working.
Create vcr.rb inside feature/support folder and add this:
If this doesn’t work then follow the detailed documentation at Relish to get it working with cucumber
If you are using Cucumber with Rails 3 or Rails 4, you might face this issue.
You would have obviously followed the Cucumber guide to set up cucumber with Rails 4.
When you run cucumber it throws error “No known ORM was detected! Is ActiveRecord, DataMapper, MongoMapper, Mongoid, or CouchPotato loaded? (DatabaseCleaner::NoORMDetected)”.
What causes this problem
When you follow cucumber guide, it ask you to add this snippet in Gemfile
And when you execute command to generate cucumber, it creates env.rb inside features/support folder
Entries in gemfile and env.rb file for database doesn’t allow you to run your cucumber tests and always throw error for not finding the database, snippet of env.rb is shown below
How to resolve
If you are not using any database in your application and using Rails 3.x or 4.x with latest version of cucumber, you will have to do following things.
- Commented out the lines shown above in env.rb
- Uninstall database cleaner by running command “gem uninstall database_cleaner“
- Also remove database cleaner from your gemfile, so that next time you do bundle install, this problem will not haunt you.
- Some of the group forums also suggest to mark “DatabaseCleaner.strategy = :none“, but it didn’t work in my case as “none” is not a valid input for strategy, it only accept “transaction” and “truncation”; So I would rather comment it out or delete those lines.
Hope this helps, my motivation behind documenting it is unable to find straight forward solution anywhere.
Moving between jobs and setting up new machine can be quite painful at times, I recently moved into new assignment and faced the challenge so to avoid pain for other just summarising the steps I followed for smooth Installation.
1. Install Xcode and the Command Line Tools
If you don’t have Xcode installed I suggest to install Xcode from the Mac App Store and install the command line tools in Xcode Preferences -> Downloads.
2. Install Homebrew
- ruby -e “$(curl -fsSL https://raw.github.com/mxcl/homebrew/go)”
Now, run brew doctor to check everything is as expected before we continue.:
- brew doctor
If you get error: No such file or directory – /usr/local/Cellar
Run the following:
- sudo mkdir /usr/local/Cellar
- sudo chown -R `whoami` /usr/local
3. Install RVM
- curl -L get.rvm.io | bash
After this is complete, execute the following in order to use RVM in your current shell
- source ~/.rvm/scripts/rvm
4. Setup ~/.profile
Add the following to your ~/.profile in order to source RVM everytime you run Terminal.app:
- [[ -s “$HOME/.rvm/scripts/rvm” ]] && source “$HOME/.rvm/scripts/rvm”
5. Check RVM Requirements
- rvm requirements
If you have any missing required packages you will need to install them before continuing by running brew install .
If you need to install apple-gcc42 and get an error: No available formula for apple-gcc42
Run the following:
- brew tap homebrew/dupes
If you get an error after running this: Already tapped!
Instead of repairing, run the following:
- brew tap –repair homebrew/dupes
Now you can continue and install apple-gcc42:
From the “Missing required packages: …” line above, for example I can now execute the following:
- brew install autoconf automake libtool pkg-config apple-gcc42 libyaml readline libxml2 libxslt libksba openssl sqlite
6. Run brew doctor again to make sure everything checks out
Execute the following:
- brew doctor
If you get an error or warning about your PATH. Such as:
- Warning: /usr/bin occurs before /usr/local/bin
Open your ~/.profile and add the following line to the top (or bottom, it shouldn’t matter):
- export PATH=/usr/local/bin:$PATH
Or Augment your .bash_profile to have
- export PATH=”/usr/local/bin:/usr/local/sbin:~/bin:$PATH”
Now run: brew doctor
7. It’s now time to install Ruby 2.0.0:
First run the following commands:
- rvm get head
- rvm requirements
If you don’t get any errors you can finally install Ruby 2.0.0:
- rvm install 2.0.0
To set as your current version of Ruby run the following command:
- rvm use 2.0.0
To make it the default Ruby:
- rvm default 2.0.0
Now every time you open Terminal.app Ruby 2.0.0 will be default. You can always check which version of Ruby you have using the following command:
- ruby -v
and where it’s located executing the command:
- which ruby
You are now setup to run Ruby 2.0.0 on Mac OS X 10.8 Mountain Lion.