【问题标题】:Guard not evaluating correct fileGuard 未评估正确的文件
【发布时间】:2014-08-14 04:06:59
【问题描述】:

我正在使用 rspec 3.0 和 Spring on Rails 4.1 运行 Guard。当我尝试为我的应用程序编写视图规范时,guard 没有注意到正在保存的正确文件。例如,如果我将视图规范保存在“/spec/views/api/v1/registrations/create.json.jbuilder_spec.rb”,guard 将运行“/spec/controllers/api/v1/registrations_controller_spec.rb”的规范”。我的 Guardfile 如下:

guard :rspec, cmd: 'spring rspec', all_on_start: false do

  watch(%r{^spec/models/.+integration_spec\.rb$})
  watch(%r{^spec/helpers/.+_spec\.rb$})
  watch(%r{^spec/routing/.+_spec\.rb$})
  watch(%r{^spec/requests/.+_spec\.rb$})
  watch(%r{^spec/views/.+_spec\.rb$})
  watch(%r{^spec/controllers/.+_spec\.rb$})

  watch(%r{^lib/(.+)\.rb$})     { |m| "spec/lib/#{m[1]}_spec.rb" }
  watch('spec/spec_helper.rb')  { "spec" }

  watch(%r{^app/(.+)\.rb$})                           { |m| "spec/#{m[1]}_spec.rb" }
  watch(%r{^app/(.*)(\.erb|\.haml|\.slim)$})          { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
  watch(%r{^app/controllers/(.+)_(controller)\.rb$})  { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
  watch(%r{^spec/support/(.+)\.rb$})                  { "spec" }
  watch('config/routes.rb')                           { "spec/routing" }
  watch('app/controllers/application_controller.rb')  { "spec/controllers" }

  watch(%r{^app/views/(.+)/.*\.(erb|haml|slim)$})     { |m| "spec/features/#{m[1]}_spec.rb" }
end

如果我注释掉除视图之一之外的所有“规范”正则表达式,guard 仍然具有我上面解释的相同行为。此外,这发生在我编写的每个视图规范中。我不确定为什么这个正则表达式会出现这种情况,但感谢您提供任何帮助。

【问题讨论】:

    标签: rspec-rails guard


    【解决方案1】:

    我发现了问题所在。事实证明,gem guard-rspec 有一个默认的 failed_mode,它被设置为焦点(前 10 个失败的规范,无论你显然运行什么)。通过在我的 Guardfile 中将此设置为“无”,它解决了我的问题。

    【讨论】:

      猜你喜欢
      • 2011-08-04
      • 1970-01-01
      • 2019-09-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-03-09
      • 2016-05-21
      • 1970-01-01
      相关资源
      最近更新 更多