require 'autotest/redgreen' require 'autotest/timestamp' module Autotest::Growl def self.growl(title, msg, img, pri=0, sticky="") system "growlnotify -n autotest --image #{img} -p #{pri} -m #{msg.inspect} #{title} #{sticky}" end Autotest.add_hook :ran_command do |at| image_root = "~/.autotest_images" results = [at.results].flatten.join("\n") output = results.slice(/(\d+)\s+examples?,\s*(\d+)\s+failures?(,\s*(\d+)\s+not implemented)?/) if output failures = $~[2].to_i pri = failures == 0 ? 0 : 2 image = case failures when 1...5 "#{11 + rand(17-11)}.png" when 6...10 "#{21 + rand(27-21)}.png" when 11...15 "#{31 + rand(37-31)}.png" when 16...20 "#{41 + rand(47-41)}.png" when 21...100000000 "#{51 + rand(57-51)}.png" else "pass.png" end growl("Test Results \\(#{File.basename(Dir.pwd)}\\)", output, File.join(image_root, image), pri) end end end