Skip to content

Instantly share code, notes, and snippets.

@dchelimsky
Created October 6, 2008 18:58
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 dchelimsky/15095 to your computer and use it in GitHub Desktop.
Save dchelimsky/15095 to your computer and use it in GitHub Desktop.
module Autotest::Growl
def self.growl title, msg, img, pri=0, stick=""
system "growlnotify -n autotest --image #{img} -p #{pri} -m #{msg.inspect} #{title} #{stick}"
end
def self.strip_command_line_format(text)
result = text.gsub(/\e\[(\d+)m/,"")
result.gsub!("\n","")
end
Autotest.add_hook :ran_command do |at|
results = [at.results].flatten.join("\n")
output = results.find do |line| line =~ /(\d+)\s+examples?,\s(\d+)\s+failures?/ end
if output
if $~[2].to_i > 0
growl "Examples", "#{self.strip_command_line_format(output)}", '~/Library/autotest/rails_fail.png'
else
growl "Examples", "#{self.strip_command_line_format(output)}", '~/Library/autotest/rails_ok.png'
end
end
end
end
Autotest.add_hook :initialize do |at|
unless ARGV.empty?
if Dir["spec"].empty?
at.find_directories = ARGV.length == 1 ? ["spec/#{ARGV.first}","lib/#{ARGV.first}"] : ARGV.dup
else
at.find_directories = ARGV.length == 1 ? ["spec/#{ARGV.first}","app/#{ARGV.first}"] : ARGV.dup
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment