Skip to content

Instantly share code, notes, and snippets.

@leanucci
Created January 6, 2011 23:10
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 leanucci/768807 to your computer and use it in GitHub Desktop.
Save leanucci/768807 to your computer and use it in GitHub Desktop.
my autotest script
require 'rubygems'
require 'autotest/fsevent'
require 'redgreen'
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
IMAGE_ROOT = "~/Pictures/autotest/"
def self.notify_unit(results)
output = results.slice(/(\d+)\stests,\s(\d+)\sassertions,\s(\d+)\sfailures,\s(\d+)\serrors/)
if output
if $~[3].to_i > 0 || $~[4].to_i > 0
cnt = [(9 + $~[3].to_i + $~[4].to_i) / 10 * 10, 50].min
growl "=====[ F A I L ]=====", "#{output}", IMAGE_ROOT + "fail#{cnt}.png", 2
else
growl "=====[ P A S S ]=====", "#{output}", IMAGE_ROOT + "pass.png"
end
end
end
def self.notify_rspec(results)
output = results.slice(/(\d+)\s+examples?,\s*(\d+)\s+failures?(,\s*(\d+)\s+pending)?/)
if output =~ /[1-9]\sfailures?/
cnt = [$~[2] / 10 * 10, 50].min
growl "=====[ F A I L ]=====", "#{output}", IMAGE_ROOT + "fail#{cnt}.png", 2
else
growl "=====[ P A S S ]=====", "#{output}", IMAGE_ROOT + "rails_ok.png"
end
end
Autotest.add_hook :ran_command do |at|
results = [at.results].flatten.join("n")
case at.results[-1].split(",").first.split(" ")[1]
when "tests"
notify_unit(results)
when "examples"
notify_rspec(results)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment