我有一个功能规格,如spec/features/awesome_feature_spec.rb需要spec/shared_examples/awesome_spec.rb.后者包含我正在使用的所有shared_examples awesome_feature_spec.rb.当一个示例失败并且我编辑一个文件来修复它并保存它时,guard会尝试再次运行该示例,但它会直接运行awesome_feature.rb而不是awesome_feature_spec.rb因为失败的共享示例所在awesome_feature.rb.这当然会导致错误,因为它需要运行awesome_feature_spec.rb,这是实际的功能规范.
这就是我的Guardfile的样子:
guard :rspec do
watch(%r{^spec/.+_spec\.rb$})
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
watch('spec/spec_helper.rb') { "spec" }
# Rails example
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" }
# Capybara features specs
watch(%r{^app/views/(.+)/.*\.(erb|haml|slim)$}) { |m| "spec/features/#{m[1]}_spec.rb" }
watch(%r{^spec/shared_examples.*/(.+)\.rb$}) { |m| "spec/features/#{m[1]}_spec.rb" }
# Turnip features and steps …Run Code Online (Sandbox Code Playgroud)