【问题标题】:undefined method `visit` rspec/capybara未定义的方法`visit` rspec/capybara
【发布时间】:2014-09-01 20:23:04
【问题描述】:

我正在关注 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

【问题讨论】:

  • 您的spec_helper 文件中有什么内容?
  • 如果您使用 Capybara >= 2.0.0,请尝试将您的规范移动到 spec/features/ 目录中。

标签: ruby-on-rails rspec capybara


【解决方案1】:

也许你只是错过了:

config.include Capybara::DSL

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多