未定义的方法`访问`rspec / capybara

时间:2014-09-01 20:23:05

标签: ruby-on-rails 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

1 个答案:

答案 0 :(得分:0)

也许你错过了:

config.include Capybara::DSL

你也可以查看相同的问题here