Guest User

Untitled

a guest
Apr 19th, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. # Run me with:
  2. #
  3. # $ watchr specs.watchr.rb
  4.  
  5. # --------------------------------------------------
  6. # Convenience Methods
  7. # --------------------------------------------------
  8. def all_test_files
  9. Dir['test/**/*_test.rb'] - ['test/test_helper.rb']
  10. end
  11.  
  12. def run(cmd)
  13. puts(cmd)
  14. system(cmd)
  15. end
  16.  
  17. def run_all_tests
  18. cmd = "ruby -rubygems -Ilib -e'%w( #{all_test_files.join(' ')} ).each {|file| require file }'"
  19. run(cmd)
  20. end
  21.  
  22. def run_test(suspect)
  23. run("ruby -rubygems -Ilib #{suspect}")
  24. end
  25.  
  26. # --------------------------------------------------
  27. # Watchr Rules
  28. # --------------------------------------------------
  29. watch( '^test.*/.*_test\.rb' ) { |m| run_test(m[0]) }
  30. watch( '^lib/(.*)\.rb' ) { |m| run_test("test/#{m[1]}_test.rb") }
  31. watch( '^lib/.*/(.*)\.rb' ) { |m| run_test("test/#{m[1]}_test.rb") }
  32. watch( '^test/test_helper\.rb' ) { run_all_tests }
  33.  
  34. # --------------------------------------------------
  35. # Signal Handling
  36. # --------------------------------------------------
  37. # Ctrl-\
  38. Signal.trap('QUIT') do
  39. puts " --- Running all tests ---\n\n"
  40. run_all_tests
  41. end
  42.  
  43. # Ctrl-C
  44. Signal.trap('INT') { abort("\n") }
Add Comment
Please, Sign In to add comment