使用 Guard 运行我的规范时遇到一个奇怪的问题。
我正在运行一个使用 Capybara“功能”/“场景”语法的功能规范。我也在使用 Spring。
如果我运行 rspec spec
一切正常或 spring rspec
在控制台或 rspec
在 Guard shell 中。但是,当监视的规范由 Guard 自动运行时,我收到以下错误:
/spec/features/navigation_spec.rb:1:in
<top (required)>': undefined method
feature' for main:Object (NoMethodError)
为什么它不只在这个特定的上下文中使用 Capybara 语法?
这是相关的代码:
保护文件
guard :rspec, :spring => true do
watch(%r{^spec/.+_spec\.rb$})
end
规范/功能/navigation_spec.rb
feature "navigation" do
context "When on the home page" do
before { visit "/" }
scenario "I should see the navigation header" do
expect(page).to have_selector("div.navigation")
end
end
end
规范/spec_helper.rb
require 'capybara/rspec'
最佳答案
对于将来可能遇到类似问题的任何人,我忘了包括 require 'spec_helper'
在功能规范中(就像一个白痴)。
关于ruby-on-rails - 当 Guard 在监视文件中运行规范时,Rspec/Capybara "feature"方法未定义,手动运行时有效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19715220/