Guest User

Untitled

a guest
Feb 20th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.71 KB | None | 0 0
  1. require 'autotest/redgreen'
  2.  
  3. Autotest.send(:alias_method, :real_make_test_cmd, :make_test_cmd)
  4. Autotest.send(:define_method, :make_test_cmd) do |*args|
  5. real_make_test_cmd(*args).sub('test/unit', %[rubygems -e "require 'redgreen'"])
  6. end
  7.  
  8. Autotest.add_hook :initialize do |autotest|
  9. autotest.add_exception(/^\.\/vendor/)
  10. autotest.add_exception(/\.svn/)
  11. autotest.add_exception(/\.git/)
  12. autotest.add_mapping(/stories\/all.rb/) do |f, _|
  13. autotest.files_matching %r%^spec/(controllers|helpers|lib|models|views)/.*\.rb$%
  14. end
  15. end
  16.  
  17. module Autotest::Growl
  18.  
  19. def self.growl title, msg, pri=-1, stick=""
  20. system "growlnotify -n autotest -p #{pri} -m #{msg.inspect} #{title} #{stick}"
  21. end
  22.  
  23. def self.parse_results(autotest_results)
  24. keys = %w(test example failure error pending fixed)
  25. output = (autotest_results.last||"")
  26. results = {}
  27. keys.each do |key|
  28. output =~ /(\d+) #{key}/
  29. results[key] = $1.to_i || 0
  30. end
  31. results
  32. end
  33.  
  34. Autotest.add_hook :ran_command do |autotest|
  35. autotest_output = (autotest.results.last||"").slice(/(\d+) (test||example)[^\e]*/)
  36. output = parse_results(autotest.results)
  37. if output['failure'] == 0 && output['error'] == 0 && output['pending'] == 0
  38. growl "Test Results", autotest_output, -2
  39. elsif output['failure'] == 0 && output['error'] == 0 && output['pending'] > 0
  40. growl "Test Results", autotest_output, -1
  41. elsif output['failure'] == 0 && output['error'] == 0
  42. growl "Test Results", autotest_output, 0
  43. elsif output['fixed'] > 0
  44. growl "Test Results", autotest_output, 0
  45. else
  46. growl "Test Results", autotest_output, 1#, "-s"
  47. end unless autotest_output.nil?
  48. end
  49.  
  50. end
Add Comment
Please, Sign In to add comment