【发布时间】:2013-11-11 23:20:30
【问题描述】:
我在使用 Guard 运行我的规范时遇到了一个奇怪的问题。
我正在运行使用 Capybara“功能”/“场景”语法的功能规范。我也在使用 Spring。
如果我在控制台中运行rspec spec 或spring rspec 或在Guard shell 中运行rspec,一切正常。但是,当监视的规范由 Guard 自动运行时,我收到以下错误:
/spec/features/navigation_spec.rb:1:in
<top (required)>': undefined methodfeature' for main:Object (NoMethodError)
为什么它不只在这个特定的上下文中使用 Capybara 语法?
以下是相关代码:
保护文件
guard :rspec, :spring => true do
watch(%r{^spec/.+_spec\.rb$})
end
spec/features/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/spec_helper.rb
require 'capybara/rspec'
【问题讨论】:
-
当您尝试从其他上下文中仅运行这一规范时会发生什么?我想知道是不是没有
require 'spec_helper.rb。 -
你在做某事。如果我只是从命令行运行一个规范,我会得到同样的错误。那么问题是什么?我还不是很清楚。
-
没关系。知道了。忘记在功能规范中包含
require 'spec_helper'。谢谢!
标签: ruby-on-rails spring rspec capybara guard