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...
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.
6 Answers
You have to add config.include Capybara::DSL to rails_helper.rb, and not into spec_helper.rb. It worked for me perfectly!
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
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.
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:
I'm added config.include Capybara::DSL to rails_helper.rb, and not into spec_helper.rb. and it really helped.
I also countered to this question. I was learning MOOC, and test file was copyed from another place. Because .repec was hide file, so when I copied, this file was not copied. I use Command + shift +. to show the file and copy it to project root directory, and the issue was solved.