Uninitialized constant Capybara

I have a problem testing on rails with Capybara. Whenever I run it, it tells me that I have an “uninitialized Capybara constant (NameError)” in my spec_helper.rb file.

I follow this guide: http://www.railstutorial.org/book/static_pages#code-capybara_dsl

This is my spec_helper.rb

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

and I'm trying to run this test static_pages_spec.rb

require 'spec_helper'
  describe "Static pages" do

it "should have the content 'Sample App'" do
  visit '/static_pages/home'
  expect(page).to have_content('Sample App')
end 

If there is any other additional information, just let me know.

-------- UPDATE ----------------

I understood the problem. Rspec version I create the rails_helper.rb file in the spec folder. I had to do:

require 'capybara/rspec'

in this file and config.include Capybara :: DSL in configurations.

----- ------------ : , "" - undefined.

 undefined method `visit' for #<RSpec::ExampleGroups::StaticPages::AboutPage:0x000001033f5d50>

"capybara" "capybara/dsl", , .

+4
3

, capybara, rspec "rails_helper", , rails_helper, spec_helper. speck spec

require 'rails_helper'

, , "spec_helper", rspec.

,

config.include(Capybara::DSL)

rails, , , css, , , , . , . , .

+1

, Capybara Gemfile. , .

, ; - .:)

Capybara, capybara Gemfile. "uninitialized constant Capybara (NameError)", rails_helper:

$ rspec spec
Running via Spring preloader in process 17470
/Users/Art/RailsProjects/MyRailsProj/spec/rails_helper.rb:67:in `block in <top (required)>': uninitialized constant Capybara (NameError)

, O.P., , Capybara, , : rails_helper spec_helper.

config.include(Capybara::DSL)

rails_helper.rb.

, Capybara, spec_helper, .

+1

Add require 'capybara/rails'to Test Assistant

0
source

Source: https://habr.com/ru/post/1543124/


All Articles