test.watchr in libnotify-0.4.0 vs test.watchr in libnotify-0.5.0
- old
+ new
@@ -1,15 +1,50 @@
#!/usr/bin/env watchr
-begin
- require File.join(ENV["HOME"], ".watchr.test.rb")
-rescue LoadError
- warn "Unable to load #{File.join(ENV["HOME"], ".watchr.test.rb")}"
- warn "You might try this: http://gist.github.com/raw/273574/8804dff44b104e9b8706826dc8882ed985b4fd13/.watchr.test.rb"
- exit
+#!/usr/bin/env watchr
+
+def run(cmd)
+ puts(cmd)
+ system cmd
end
+def run_test_file(file)
+ clear
+ run "ruby -rubygems -Ilib:test #{file}"
+end
+
+def run_tests
+ clear
+ run "rake"
+end
+
+def clear
+ system "clear"
+end
+
+def underscore(file)
+ file.gsub('/', '_')
+end
+
+@interrupted = false
+
+Signal.trap 'QUIT' do
+ run_tests
+end
+
+Signal.trap 'INT' do
+ if @interrupted then
+ abort("\n")
+ else
+ puts "Interrupt a second time to quit"
+ @interrupted = true
+ Kernel.sleep 1.5
+ # raise Interrupt, nil # let the run loop catch it
+ run_tests
+ end
+end
+
run_tests
-watch('test/test_.*\.rb') {|md| run md[0] }
-watch('lib/(.*)\.rb') {|md| run "test/test_#{underscore(md[1])}.rb" }
+watch('test/test_.*\.rb') {|md| run_test_file md[0] }
+watch('lib/(.*)\.rb') {|md| run_test_file "test/test_#{underscore(md[1])}.rb" }
watch('test/helper.rb') { run_tests }