Created
October 6, 2008 18:58
-
-
Save dchelimsky/15095 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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