Skip to content

Instantly share code, notes, and snippets.

@Emerson
Created March 12, 2013 03:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Emerson/5140181 to your computer and use it in GitHub Desktop.
Save Emerson/5140181 to your computer and use it in GitHub Desktop.
Example Guard File for Rails 4 and Minitest::Unit
guard 'minitest' do
# with Minitest::Unit
watch(%r|^test/(.*)\/?test_(.*)\.rb|)
watch(%r|^lib/(.*)([^/]+)\.rb|) { |m| "test/#{m[1]}test_#{m[2]}.rb" }
watch(%r|^test/test_helper\.rb|) { "test" }
# Rails 4 - App Files
watch(%r|^app/controllers/(.*)\.rb|) { |m| "test/controllers/#{m[1]}_test.rb" }
watch(%r|^app/helpers/(.*)\.rb|) { |m| "test/helpers/#{m[1]}_test.rb" }
watch(%r|^app/models/(.*)\.rb|) { |m| "test/unit/#{m[1]}_test.rb" }
# Rails 4 - Test Files
watch(%r|^test/controllers/(.*)\.rb|) { |m| "test/controllers/#{m[1]}.rb" }
watch(%r|^test/helpers/(.*)\.rb|) { |m| "test/helpers/#{m[1]}.rb" }
watch(%r|^test/integration/(.*)\.rb|) { |m| "test/integration/#{m[1]}.rb" }
watch(%r|^test/mailers/(.*)\.rb|) { |m| "test/mailers/#{m[1]}.rb" }
watch(%r|^test/models/(.*)\.rb|) { |m| "test/models/#{m[1]}.rb" }
end
@Emerson
Copy link
Author

Emerson commented Mar 12, 2013

Works on my machine with
gem 'guard' gem 'guard-minitest'

@artempyanykh
Copy link

You may have a typo on line 11. Should be

watch(%r|^app/models/(.*)\.rb|)      { |m| "test/models/#{m[1]}_test.rb" }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment