Skip to content

Instantly share code, notes, and snippets.

@benpickles
Created January 21, 2009 19:23
Show Gist options
  • Save benpickles/50132 to your computer and use it in GitHub Desktop.
Save benpickles/50132 to your computer and use it in GitHub Desktop.
require 'autotest/redgreen'
module Autotest::Growl
def self.notify(title, message, image, priority = 1, sticky = '')
`growlnotify --image #{image} -p #{priority} -m #{message.inspect} #{title} #{sticky}`
end
Autotest.add_hook :ran_command do |at|
results = [at.results].flatten.join("\n")
if output = results.slice(/(\d+)\s+examples?,\s*(\d+)\s+failures?/)
# Rspec.
examples = $1.to_i
failures = $2.to_i
damage = [failures, 5].min
elsif output = results.slice(/(\d+)\s+tests?,\s*(\d+)\s+assertions?,\s*(\d+)\s+failures?,\s*(\d+)\s+errors?/)
# Test::Unit.
tests = $1.to_i
assertions = $2.to_i
failures = $3.to_i
errors = $4.to_i
damage = [failures + errors, 5].min
end
if damage && damage > 0
notify('FAIL', output, "~/Pictures/autotest/fail#{damage}.png", 2)
else
notify('Pass', output, "~/Pictures/autotest/pass.png")
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment