jimrhoskins (owner)

Revisions

gist: 137961 Download_button fork
public
Description:
Autotest file that plays a random sound on state change
Public Clone URL: git://gist.github.com/137961.git
Embed All Files: show embed
.autotest #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# -*- 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