Skip to content

Instantly share code, notes, and snippets.

@jdtornow
Created June 11, 2012 21:51
Show Gist options
  • Save jdtornow/2912972 to your computer and use it in GitHub Desktop.
Save jdtornow/2912972 to your computer and use it in GitHub Desktop.
guard 'minitest' do
# Run all tests if the test_helper.rb file is changed
watch('test/test_helper.rb') { 'test' }
# Run all tests if we change a .rb file in lib or config
#watch(%r{^(lib|config)/(.*)\.rb}) { 'test' }
# If a model is changed, run the corresponding unit test file
watch(%r{^app/models/(.*)\.rb$}) { |m| "test/unit/#{m[1]}_test.rb" }
# If an asset model is changed, run all asset inherited unit tests
watch(%r{^app/models/(asset|image|document)\.rb$}) { |m| [ "test/unit/asset_test.rb", "test/unit/document_test.rb", "test/unit/image_test.rb" ] }
# If a controller is changed, run the corresponding functional test file
watch(%r{^app/controllers/(.*)\.rb$}) { |m| "test/functional/#{m[1]}_test.rb" }
# If a helper file is changed, and a unit test exists for it, run that test
watch(%r{^app/helpers/(.*)_helper\.rb$}) { |m| [ "test/unit/helpers/#{m[1]}_helper_test.rb", "test/functional/#{m[1]}_controller_test.rb" ] }
# If a mailer is changed, run the corresponding unit test file
watch(%r{^app/mailers/(.*)\.rb$}) { |m| "test/functional/#{m[1]}_test.rb" }
# Watch all test files and re-run them if they change.
watch(%r{^test/(.*)_test\.rb$})
# Watch fixtures and factories and re-run all tests if they change
watch(%r{^test/(factories|fixtures|uploads)/(.*)}) { 'test' }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment