Skip to content
Browse files

Update specs.watchr script

  • Loading branch information...
1 parent 9c97f12 commit f677874cf46689d1dfbe23ec447f0a06e7977ef6 @mynyml mynyml committed Jan 26, 2010
Showing with 23 additions and 24 deletions.
  1. +23 −24 specs.watchr
View
47 specs.watchr
@@ -1,38 +1,37 @@
# Run me with:
-#
# $ watchr specs.watchr
# --------------------------------------------------
-# Helpers
+# Rules
# --------------------------------------------------
-def run(cmd)
- puts(cmd)
- system(cmd)
-end
-
-def run_all_tests
- # see Rakefile for the definition of the test:all task
- system( "rake -s test:all VERBOSE=true" )
-end
+watch( '^test.*/test_.*\.rb' ) { |m| ruby( "%s" % m[0] ) }
+watch( '^lib/(.*)\.rb' ) { |m| ruby( "test/test_%s.rb" % m[1] ) }
+watch( '^lib/watchr/(.*)\.rb' ) { |m| ruby( "test/test_%s.rb" % m[1] ) }
+watch( '^lib/watchr/event_handlers/(.*)\.rb' ) { |m| ruby( "test/event_handlers/test_%s.rb" % m[1] ) }
+watch( '^test/test_helper\.rb' ) { ruby tests }
# --------------------------------------------------
-# Watchr Rules
+# Signal Handling
# --------------------------------------------------
-watch( '^test.*/test_.*\.rb' ) { |m| run( "ruby -rubygems -I.:lib %s" % m[0] ) }
-watch( '^lib/(.*)\.rb' ) { |m| run( "ruby -rubygems -I.:lib test/test_%s.rb" % m[1] ) }
-watch( '^lib/watchr/(.*)\.rb' ) { |m| run( "ruby -rubygems -I.:lib test/test_%s.rb" % m[1] ) }
-watch( '^lib/watchr/event_handlers/(.*)\.rb' ) { |m| run( "ruby -rubygems -I.:lib test/event_handlers/test_%s.rb" % m[1] ) }
-watch( '^test/test_helper\.rb' ) { run_all_tests }
+Signal.trap('QUIT') { ruby tests } # Ctrl-\
+Signal.trap('INT' ) { abort("\n") } # Ctrl-C
# --------------------------------------------------
-# Signal Handling
+# Helpers
# --------------------------------------------------
-# Ctrl-\
-Signal.trap('QUIT') do
- puts " --- Running all tests ---\n\n"
- run_all_tests
+def ruby(*paths)
+ run "ruby #{gem_opt} -I.:lib:test -e'%w( #{paths.flatten.join(' ')} ).each {|p| require p }'"
end
-# Ctrl-C
-Signal.trap('INT') { abort("\n") }
+def tests
+ Dir['test/**/test_*.rb'] - ['test/test_helper.rb']
+end
+def run( cmd )
+ puts cmd
+ system cmd
+end
+
+def gem_opt
+ defined?(Gem) ? "-rubygems" : ""
+end

0 comments on commit f677874

Please sign in to comment.
Something went wrong with that request. Please try again.