Created
September 18, 2009 13:41
-
-
Save mynyml/189052 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Run me with: | |
# | |
# $ watchr specs.watchr.rb | |
# -------------------------------------------------- | |
# Convenience Methods | |
# -------------------------------------------------- | |
def all_test_files | |
Dir['test/**/test_*.rb'] - ['test/test_helper.rb'] | |
end | |
def run(cmd) | |
puts(cmd) | |
system(cmd) | |
end | |
def run_all_tests | |
cmd = "ruby -rubygems -Ilib -e'%w( #{all_test_files.join(' ')} ).each {|file| require file }'" | |
run(cmd) | |
end | |
# -------------------------------------------------- | |
# Watchr Rules | |
# -------------------------------------------------- | |
watch( '^test.*/test_.*\.rb' ) { |m| run( "ruby -rubygems %s" % m[0] ) } | |
watch( '^lib/(.*)\.rb' ) { |m| run( "ruby -rubygems test/test_%s.rb" % m[1] ) } | |
watch( '^lib/.*/(.*)\.rb' ) { |m| run( "ruby -rubygems test/test_%s.rb" % m[1] ) } | |
watch( '^test/test_helper\.rb' ) { 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") } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment