I just upgraded my Capybara Gem from version 1 to 2.1.0 (latest). Based on Capybara Readme, I added this following lines to my spec_helper.rb inside Spork.prefork block
require 'capybara/rspec'
require 'capybara/rails'
But, I got an error
/home/user_1/.rvm/gems/ruby-1.9.3-p392/gems/capybara-2.1.0/lib/capybara/rails.rb:6:in `block (2 levels) in <top (required)>': uninitialized constant Rails (NameError)
Did I miss something in order capybara to work properly ?
Make sure you require 'rspec/rails' first:
require 'rspec/rails'
require 'capybara/rspec'
require 'capybara/rails'
If you require 'capybara/rails' first, you'll get that error.
In your spec_helper.rb file, this error can be caused from adding the require 'capybara/rails'
line in the top of the file's code.
Instead, if you look about half-way down that auto-generated spec_helper.rb file, you will see something like this:
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'rspec/autorun'
Add the require 'capybara/rails'
line after those lines so that it looks like:
ENV["RAILS_ENV"] ||= 'test'
require File.expand_path("../../config/environment", __FILE__)
require 'rspec/rails'
require 'rspec/autorun'
require 'capybara/rails' #######
(you don't need the hashes, those were just to highlight the insertion location)
Hopefully this helps you or someone else out there...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With