簡體   English   中英

未定義的方法`visit` rspec / capybara

[英]undefined method `visit` rspec/capybara

我正在關注rspec上的Michael Hartls教程,但出現此錯誤

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'

用於rspec測試。

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

我不相信出現此錯誤的原因是測試用例失敗,而是這樣的:

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

我不確定為什么會有未定義的方法visit

也許您只是錯過了:

config.include Capybara::DSL

你也可以在這里看到相同的問題

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM