Skip to content

Instantly share code, notes, and snippets.

@zorab47
Created November 16, 2010 14:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zorab47/701843 to your computer and use it in GitHub Desktop.
Save zorab47/701843 to your computer and use it in GitHub Desktop.
Rails Watchr
def run_all_tests
# see Rakefile for the definition of the test:all task
system( "rake -s test" )
end
def run(cmd)
puts(cmd)
system(cmd)
end
watch( '^test/(functional|integration|unit)/.*\.rb' ) { |m| run("ruby -I.:lib:test %s" % m[0]) }
watch( '^test/fixtures/.*\.yml' ) { run_all_tests }
watch( '^app/controllers/(.*)\.rb' ) { |m| run("ruby -I.:lib:test test/functional/%s_test.rb" % m[1]) }
watch( '^app/views/(.*)/.*' ) { |m| run("ruby -I.:lib:test test/functional/%s_controller_test.rb" % m[1]) }
watch( '^app/models/(.*)\.rb' ) { |m| run("ruby -I.:lib:test test/unit/%s_test.rb" % m[1]) }
# helper unit tests
watch( '^test/unit/helpers/.*\.rb' ) { |m| run("ruby -I.:lib:test %s" % m[0]) }
watch( '^app/helpers/(.*)\.rb' ) { |m| run("ruby -I.:lib:test test/unit/helpers/%s_test.rb" % m[1]) }
watch( '^test/test_helper.rb|config/((boot|environment(s/test)?).rb|database.yml)' ) { run_all_tests }
# --------------------------------------------------
# Signal Handling
# --------------------------------------------------
# Ctrl-\
Signal.trap('QUIT') do
puts " --- Running all tests ---\n\n"
run_all_tests
end
# Ctrl-C
Signal.trap('INT') { abort("\n") }
# vim: syntax=ruby sw=2 ts=2 expandtab
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment