Created
August 22, 2008 20:34
-
-
Save rick/6849 to your computer and use it in GitHub Desktop.
This file contains 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
require 'autotest/redgreen' | |
require 'autotest/timestamp' | |
require '~/autotest/sound/sound.rb' | |
Autotest::Sound.sound_path = "~/autotest/sound/sound_fx/current/" | |
Autotest.add_hook :initialize do |at| | |
%w{.svn .hg .git vendor db index public tmp log}.each {|exception|at.add_exception(exception+'/')} | |
end | |
Autotest.send(:alias_method, :real_find_files, :find_files) | |
Autotest.send(:define_method, :find_files) do |*args| | |
real_find_files.reject do |k, v| | |
if (ENV['AUTOTEST'] and !ENV['AUTOTEST'].empty?) | |
!Regexp.new(ENV['AUTOTEST']).match(k) | |
end | |
end | |
end | |
TEST_THRESHOLD = 10 | |
RATIO_THRESHOLD = 0.5 | |
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 | |
Autotest.add_hook :ran_command do |at| | |
image_root = File.expand_path('~/.autotest_images') | |
results = [at.results].flatten.join("\n") | |
output = results.slice(/(\d+)\stests?,\s(\d+)\sassertions?,\s(\d+)\sfailures?,\s(\d+)\serrors?/) | |
if output | |
tests = {} | |
tests[:total] = $~[1].to_i | |
tests[:bad] = $~[3].to_i + $~[4].to_i | |
if tests[:bad] > 0 | |
message = 'FAIL' | |
image = 'fail' | |
if tests[:bad] >= TEST_THRESHOLD and (tests[:bad] / tests[:total].to_f) >= RATIO_THRESHOLD | |
message = 'EPIC FAIL' | |
image = 'epic_fail' if File.exist?("#{image_root}/current/epic_fail.png") | |
end | |
growl message, output, "#{image_root}/current/#{image}.png", 2 | |
else | |
growl 'WIN', output, "#{image_root}/current/pass.png", 1 | |
end | |
end | |
output = results.slice(/(\d+)\sexamples?,\s(\d+)\sfailures?(?:,\s+(\d+)\s+pending)?/) | |
if output | |
tests = {} | |
tests[:examples] = $~[1].to_i | |
tests[:bad] = $~[2].to_i | |
tests[:pending] = $~[3].to_i | |
tests[:running] = tests[:examples] - tests[:pending] | |
if tests[:bad] > 0 | |
message = 'FAIL' | |
image = 'fail' | |
sound = 'red' | |
if tests[:bad] >= TEST_THRESHOLD and (tests[:bad] / tests[:running].to_f) >= RATIO_THRESHOLD | |
message = 'EPIC FAIL' | |
image = 'epic_fail' if File.exist?("#{image_root}/current/epic_fail.png") | |
end | |
growl message, output, "#{image_root}/current/#{image}.png", 2 | |
Autotest::Sound.playsound sound | |
elsif tests[:pending] > 0 | |
image = sound = 'pending' | |
message = 'Pending' | |
if tests[:pending] >= TEST_THRESHOLD and (tests[:pending] / tests[:examples].to_f) >= RATIO_THRESHOLD | |
message = 'Get to work!' | |
image = 'slacker' if File.exist?("#{image_root}/current/slacker.png") | |
end | |
growl message, output, "#{image_root}/current/#{image}.png", 0 | |
Autotest::Sound.playsound sound | |
else | |
growl 'WIN', output, "#{image_root}/current/pass.png", 1 | |
Autotest::Sound.playsound 'green' | |
end | |
end | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment