Why does Guard run ALL my RSpec specs on every change?

三世轮回 提交于 2020-01-05 10:27:22

问题


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.

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.

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

回答1:


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.

See the :all_after_pass option at https://github.com/guard/guard-rspec




回答2:


For the sake of reference, the all_on_start: false and all_after_pass: false options need to be set for each guard block. It took me awhile to finally figure out why mine behaving the same way.



来源:https://stackoverflow.com/questions/16360618/why-does-guard-run-all-my-rspec-specs-on-every-change

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!