Capybara uninitialized constant (NameError) in rails application

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

specifications / 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 a gem 'capybara', '2.1.0' in my gemfile, so I don't know what is going on.

+7
ruby-on-rails ruby-on-rails-4
source share
6 answers

I think it might work. Try adding these lines to 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 
+5
source share

You should add config.include Capybara::DSL to rails_helper.rb and not to spec_helper.rb . It worked great for me!

+18
source share

Have you already run a batch installation? You added

 require 'capybara/rails' 

in rails_helper.rb

If you are using Capybara, you can follow the instructions here .

+4
source share

I added config.include Capybara::DSL to rails_helper.rb , not in spec_helper.rb . and it really helped.

+1
source share

If you see this error in your specifications, despite importing Capybara into spec_helper.rb , adding .rspec with the --require spec_helper line to the root should solve the problem:

enter image description here

+1
source share

I also answered this question. I studied MOOC and the test file was copied from another location. Since .repec was a hidden file, therefore, when copying, this file was not copied. I am using Command + Shift +. show the file and copy it to the project root directory, and the problem was resolved.

+1
source share

All Articles