Skip to content

Instantly share code, notes, and snippets.

@Oshuma
Forked from mynyml/specs.watchr.rb
Created November 3, 2009 07:44
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 Oshuma/224873 to your computer and use it in GitHub Desktop.
Save Oshuma/224873 to your computer and use it in GitHub Desktop.
specs.watchr.rb
# 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
def run_test(suspect)
run("ruby -rubygems -Ilib #{suspect}")
end
# --------------------------------------------------
# Watchr Rules
# --------------------------------------------------
watch( '^test.*/.*_test\.rb' ) { |m| run_test(m[0]) }
watch( '^lib/(.*)\.rb' ) { |m| run_test("test/#{m[1]}_test.rb") }
watch( '^lib/.*/(.*)\.rb' ) { |m| run_test("test/#{m[1]}_test.rb") }
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