2014-09-01 79 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

相关问题