问题描述
这个测试堆栈的行为不可靠.有时,当我运行 guard 时,它与 guard-rspec gem 一起充分执行并且只会运行已更改的文件.至少,如果测试失败,它将停止使用那个修改过的文件.
This testing stack is behaving unreliably. Sometimes when I run guard, it performs adequately with the guard-rspec gem and will only run the file that has been changed. At least, if the test fails it will stop with that single modified file.
但如果该测试通过,则所有赌注都将取消.更改单个文件时,它将继续运行ALL 测试.在大型应用程序中,每次保存文件时都要看到所有测试都运行,这是非常不切实际和令人沮丧的.
But if that test passes, all bets are off. It will continue to run ALL tests when a single file is changed. On a good-sized application, this is extremely impractical and frustrating to see all tests run every time a file is saved.
我的Guardfile如下.请注意,我必须更改它指向 RSpec 规范的位置.默认情况下,它认为您将拥有一个 specs
目录,并且您的所有规范都将混杂在该目录中.我不认识任何人进行这样的测试,所以包含它是一个有趣的默认值.它应该在 specs
下寻找子目录.
My Guardfile is as follows. Notice that I had to change where it was pointing to RSpec specs. By default it thinks you are going to have a specs
directory, and that all of your specs will be all jumbled into that one directory. I don't know anybody that tests like that, so it's a funny default to include. It should be looking for subdirectories under specs
.
# A sample Guardfile
# More info at https://github.com/guard/guard#readme
guard 'spork', :cucumber => false, :rspec_env => { 'RAILS_ENV' => 'test' } do
watch('config/application.rb')
watch('config/environment.rb')
watch('config/environments/test.rb')
watch(%r{^config/initializers/.+\.rb$})
watch('Gemfile')
watch('Gemfile.lock')
watch('spec/spec_helper.rb') { :rspec }
end
guard 'rspec', :version => 2, :cli => "--drb" do
watch(%r{^spec/(.*)/(.+)_spec\.rb$})
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
watch('spec/spec_helper.rb') { "spec" }
# Rails examples
watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
watch(%r{^app/(.*)(\.erb|\.haml)$}) { |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)$}) { |m| "spec/features/#{m[1]}_spec.rb" }
watch(%r{^app/views/(.+)/.*\.(erb|haml)$}) { |m| "spec/requests/#{m[1]}_spec.rb" }
# Turnip features and steps
watch(%r{^spec/acceptance/(.+)\.feature$})
watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance' }
end
推荐答案
guard-rspec gem 有一个参数,用于控制在测试成功后是否运行所有测试.它默认为 true,但可以更改为 false 以获得您正在寻找的行为.
The guard-rspec gem has a parameter which controls whether all tests are run after a successful test. It defaults to true, but can be changed to false to get the behavior you're looking for.
请参阅 https://github.com/guard/guard-rspec
这篇关于为什么 Guard 在每次更改时都运行我的所有 RSpec 规范?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!