Posted By

sou on 03/23/08


Tagged

textmate growl with for dotautotest running


Versions (?)

ruby, rspec


 / Published in: Other
 

  1. # -*- ruby -*-
  2. require 'autotest/redgreen'
  3. require 'autotest/growl'
  4.  
  5. # NOTE Copy this to your home folder as .autotest
  6. #
  7. # Originally from http://wincent.com/knowledge-base/Setting_up_autotest_to_use_Growl
  8. #
  9. # Modifications:
  10. # * Minor refactoring to use .autotest_images directory
  11. # [Geoffrey Grosenbach http://peepcode.com]
  12. # * Test::Unit compatibility [Pat Nakajima]
  13. #
  14. module Autotest::Growl
  15.  
  16. AUTOTEST_IMAGE_ROOT = "~/.autotest_images"
  17.  
  18. # def self.growl title, msg, img, pri=0
  19. # system "growlnotify -n autotest --image #{img} -p #{pri} -m #{msg.inspect} #{title}"
  20. # end
  21.  
  22. def self.growl_fail(output)
  23. growl "FAIL", "#{output}", 2, "#{AUTOTEST_IMAGE_ROOT}/rails_fail.png"
  24. end
  25.  
  26. def self.growl_pass(output)
  27. growl "Pass", "#{output}", -2, "#{AUTOTEST_IMAGE_ROOT}/rails_ok.png"
  28. end
  29.  
  30. Autotest.add_hook :ran_command do |at|
  31.  
  32. results = [at.results].flatten.join("\n")
  33.  
  34. if results.include? 'tests'
  35. output = results.slice(/(\d+)\s+tests?,\s*(\d+)\s+assertions?,\s*(\d+)\s+failures?(,\s*(\d+)\s+errors)?/)
  36. if output
  37. $~[3].to_i + $~[5].to_i > 0 ? growl_fail(output) : growl_pass(output)
  38. end
  39. else
  40. output = results.slice(/(\d+)\s+examples?,\s*(\d+)\s+failures?(,\s*(\d+)\s+not implemented)?/)
  41. if output
  42. $~[2].to_i > 0 ? growl_fail(output) : growl_pass(output)
  43. end
  44. end
  45. end
  46.  
  47. end
  48.  

Report this snippet  

You need to login to post a comment.