Skip to content

Instantly share code, notes, and snippets.

Created January 24, 2010 05:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/285025 to your computer and use it in GitHub Desktop.
Save anonymous/285025 to your computer and use it in GitHub Desktop.
require "autotest/restart"
require "autotest/fsevent"
require 'redgreen/autotest'
$KCODE = 'U'
module Autotest::Growl
Autotest.add_hook :initialize do |autotest|
%w{.git .svn .hg .DS_Store ._* vendor tmp}.each {|exception| autotest.add_exception(exception) }
false
end
AUTOTEST_IMAGE_ROOT = "~/.autotest_images"
def self.growl title, msg, img, pri=0, sticky=""
system "growlnotify -n autotest --image #{img} -p #{pri} -m #{msg.inspect} #{title} #{sticky}"
end
def self.growl_fail(output)
growl "FAIL", "#{output}", "#{AUTOTEST_IMAGE_ROOT}/fail.png", 2
end
def self.growl_pass(output)
growl "Pass", "#{output}", "#{AUTOTEST_IMAGE_ROOT}/pass.png"
end
Autotest.add_hook :ran_command do |at|
results = [at.results].flatten.join("\n")
if results.include? 'tests'
output = results.slice(/(\d+)\s+tests?,\s*(\d+)\s+assertions?,\s*(\d+)\s+failures?(,\s*(\d+)\s+errors)?/)
if output
$~[3].to_i + $~[5].to_i > 0 ? growl_fail(output) : growl_pass(output)
end
else
output = results.slice(/(\d+)\s+examples?,\s*(\d+)\s+failures?(,\s*(\d+)\s+not implemented)?/)
if output
$~[2].to_i > 0 ? growl_fail(output) : growl_pass(output)
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment