2014-09-01 70 views
0

我上rspec以下邁克爾Hartls教程中,我得到這個錯誤未定義的方法`visit` RSpec的/水豚

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

+0

你的'spec_helper'文件是什麼? – IS04 2014-09-01 20:33:31

+0

如果您使用Capybara> = 2.0.0,請嘗試將您的規範移動到** spec/features/**目錄中。 – 2014-09-02 10:30:55

回答

0

也許你只是錯過:

config.include Capybara::DSL 

還你可以看看在同一qestion here

相關問題