Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

uninitialized constant Capybara (NameError) in rails app

c:/mowes/www/rails_projects/sample_app/spec/spec_helper.rb:4:in `block in ': uninitialized constant Capybara (NameError)

spec/spec_helper.rb

# This file is copied to spec/ when you run 'rails generate rspec:install'

RSpec.configure do |config|
  config.include Capybara::DSL
end

I have gem 'capybara', '2.1.0' in my Gemfile so I don't know what's going on.

like image 791
desbest Avatar asked Oct 17 '13 20:10

desbest


4 Answers

You have to add config.include Capybara::DSL to rails_helper.rb, and not into spec_helper.rb. It worked for me perfectly!

like image 87
Liuda Avatar answered Oct 09 '22 07:10

Liuda


I think this could work. Try adding these lines in spec_helper.rb

RSpec.configure do |config|
 config.fixture_path = "#{::Rails.root}/spec/fixtures"
 config.use_transactional_fixtures = true
 config.infer_base_class_for_anonymous_controllers = false
 config.order = "random" 
 config.include Capybara::DSL
end
like image 26
Abhinay Avatar answered Oct 09 '22 09:10

Abhinay


Did you already run bundle install? Have you added

require 'capybara/rails' 

in rails_helper.rb

If you are using Capybara you might want to follow the instructions here.

like image 42
Charles Avatar answered Oct 09 '22 09:10

Charles


If you see this error in your specs, despite importing Capybara in spec_helper.rb, adding .rspec with the line --require spec_helper to the root ought to fix the issue:

enter image description here

like image 2
Michael Schock Avatar answered Oct 09 '22 09:10

Michael Schock