Created
June 30, 2009 03:11
-
-
Save jimrhoskins/137961 to your computer and use it in GitHub Desktop.
Autotest file that plays a random sound on state change
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
# -*- ruby -*- | |
# NOTE Copy this to your home folder as .autotest | |
# | |
# Originally from http://wincent.com/knowledge-base/Setting_up_autotest_to_use_Growl | |
# | |
# Modifications: | |
# * Minor refactoring to use .autotest_images directory | |
# [Geoffrey Grosenbach http://peepcode.com] | |
# * Test::Unit compatibility [Pat Nakajima] | |
# | |
$test_status = nil | |
module Autotest::Growl | |
AUTOTEST_MEDIA_ROOT = "~/.autotest_media" | |
def self.growl title, msg, img, pri=0, sticky="" | |
system "growlnotify -n autotest --image #{img} -p #{pri} -m #{msg.inspect} -t #{title.inspect} #{sticky}" | |
end | |
def self.growl_fail(output) | |
sound("failure") | |
growl "FAIL", "#{output}", "#{AUTOTEST_MEDIA_ROOT}/fail.png", 2 | |
end | |
def self.growl_pass(output) | |
sound("success") | |
growl "Pass", "#{output}", "#{AUTOTEST_MEDIA_ROOT}/pass.png" | |
end | |
def self.sound(status) | |
return if $test_status == status | |
$test_status = status | |
if ENV['AUTOTEST_SOUNDS'] == 'true' | |
files = Dir.glob("#{File.expand_path AUTOTEST_MEDIA_ROOT}/#{status}/*.mp3") | |
file = files[rand(files.size)] | |
system "afplay #{file} &" | |
end | |
end | |
Autotest.add_hook :ran_command do |at| | |
results = [at.results].flatten.join("\n") | |
if results.include? 'tests' | |
output = results.slice(/(\d+)\s+tests?,\s*(\d+)\s+assertions?,\s*(\d+)\s+failures?(,\s*(\d+)\s+errors)?/) | |
if output | |
$~[3].to_i + $~[5].to_i > 0 ? growl_fail(output) : growl_pass(output) | |
end | |
elsif results.include? 'example' | |
output = results.slice(/(\d+)\s+examples?,\s*(\d+)\s+failures?(,\s*(\d+)\s+not implemented)?/) | |
if output | |
$~[2].to_i > 0 ? growl_fail(output) : growl_pass(output) | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment