简体   繁体   中英

undefined method `visit` rspec/capybara

I am following Michael Hartls tutorial on rspec and I am getting this error

bundle exec rspec spec/requests/static_pages_spec.rb 
F

Failures:

  1) Static pages Home page should have the content 'Sample App'
     Failure/Error: visit '/static_pages/home'
     NoMethodError:
       undefined method `visit' for #<RSpec::ExampleGroups::StaticPages::HomePage:0x007fdddbdf6a90>
     # ./spec/requests/static_pages_spec.rb:6:in `block (3 levels) in <top (required)>'

Finished in 0.00052 seconds (files took 0.1562 seconds to load)
1 example, 1 failure

Failed examples:

rspec ./spec/requests/static_pages_spec.rb:5 # Static pages Home page should have the content 'Sample App'

for the rspec test.

require 'spec_helper' 

describe "Static pages" do
    describe "Home page" do
        it "should have the content 'Sample App'" do 
            visit '/static_pages/home'
            page.should have_content('Sample App')
        end 
    end
end

I don't believe that the reason I am getting this error is the test case is failing but rather this:

NoMethodError:
           undefined method `visit' for #<RSpec:....

I am not sure why there is an undefined method visit

maybe you just missed:

config.include Capybara::DSL

also you could look to the same qestion here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM