Skip to content

Instantly share code, notes, and snippets.

@kogent
Forked from nicksieger/.autotest
Created December 3, 2008 18:58
Show Gist options
  • Save kogent/31644 to your computer and use it in GitHub Desktop.
Save kogent/31644 to your computer and use it in GitHub Desktop.
# -*- ruby -*-
module AutoGrowl
def self.pt(msg)
msg.gsub %r{\\e\[[0-9]+m?}, ''
end
def self.growl(title, msg, pri = 0)
system "/usr/local/bin/growlnotify -n autotest --image /Applications/Mail.app/Contents/Resources/Caution.tiff -p #{pri} -m #{pt msg.inspect} #{pt title.inspect}" unless RUBY_PLATFORM =~ /java/
end
def self.term(at)
if at.respond_to? :spec_command
"Spec"
else
"Test"
end
end
def self.terms(at); "#{term(at)}s"; end
Autotest.add_hook :initialize do |at|
growl "autotest", "autotest was started"
at.sleep = 2
at.add_exception(/(public|log|tmp|coverage|script|.(svn|hg|git))/)
# $v = true
end
Autotest.add_hook :red do |at|
if at.respond_to? :spec_command
results = at.results.scan(/\d\)\n([^\n]*)\n([^\n]*)\n/)
growl "#{terms(at)} Failed", "#{results.size} #{terms(at).downcase} failed", 2
results.each_with_index do |err_detail,i|
err, detail = err_detail
match = err.match(/'(.*)' FAILED/) || err.match(/in '(.*)'/)
spec = match && match[1]
growl "#{detail}", "#{spec}"
if i >= 4
growl "#{results.size - i} more", "More failures omitted"
break
end
end
else
growl "#{terms(at)} Failed", "#{at.files_to_test.size} #{terms(at).downcase} failed", 2
end
end
Autotest.add_hook :green do |at|
growl "#{terms(at)} Passed", "All #{terms(at).downcase} passed", -2
end
Autotest.add_hook :quit do |at|
growl "autotest", "autotest is exiting"
end
Autotest.add_hook :all_good do |at|
index_html = "coverage/index.html"
if File.exist?(index_html) && File.exist?("spec/spec.opts")
system("ruby -S rake spec:rcov")
total_coverage = nil
File.open(index_html).each_line do |line|
if line =~ /<tt class='coverage_total'>(\d+\.\d+)%<\/tt>&nbsp;<\/td>/
total_coverage = eval($1)
break
end
end
growl "#{term(at)} Coverage", (total_coverage < 100.0 ? "Coverage (#{total_coverage}) below 100%" : "Coverage is 100%")
else
growl "#{terms(at)} Passed", "All Good"
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment