Capybara 2.1 Error uninitialized constant Rails (NameError)

Glend Maatita picture Glend Maatita · Aug 20, 2013 · Viewed 7.8k times · Source

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 ?

Answer

bowsersenior picture bowsersenior · Sep 18, 2013

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.