Skip to content

Instantly share code, notes, and snippets.

@AlSquire
Created August 28, 2010 23:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AlSquire/555718 to your computer and use it in GitHub Desktop.
Save AlSquire/555718 to your computer and use it in GitHub Desktop.
# Growl autotest module I use with Rails 3 RC Test::Unit
module Autotest::Growl
def self.growl(title, msg, img = nil)
cmd = "growlnotify -n autotest -m \"#{msg}\" \"#{title}\""
cmd += " --image \"#{img}\"" if img
system cmd
end
Autotest.add_hook :ran_command do |at|
# Sample :
# 2 tests, 2 assertions, 1 failures, 0 errors, 0 skips
regexp = /^(\d+) tests, (\d+) assertions, (\d+) failures, (\d+) errors, (\d+) skips$/
output = at.results.detect { |r| r.match(regexp) }
if output.nil?
growl "Can't match results", "Nooo!"
else
tests, assertions, failures, errors, skips = output.match(regexp).to_a[1, 5].map(&:to_i)
if failures == 0 && errors == 0
growl "GREEN", "#{output}", "/Users/arnaud/Dev/Misc/autotest/rails_ok.png"
else
growl "FAIL", "#{output}", "/Users/arnaud/Dev/Misc/autotest/rails_fail.png"
end
end
end
end
@AlSquire
Copy link
Author

Obsolete with the autotest-growl gem

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment