Adding sound to your .autotest

Being a person with a keen auditory sense, I wanted my autotest to give me sonic feedback as well as colored growl images.

The sndplay utility I have compiled as a universal binary comes from snd (a handy app I used all the time when I was at CCRMA) sndplay has the nice feature of controlling the volume, which is important for toning down the annoyance factor.

Here are the fun audio files that I use in my .autotest. And here is the code:


require 'autotest/redgreen'

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

  Autotest.add_hook :ran_command do |at|
    output = at.results.to_s.slice(/(\d+).*errors/)
    if output =~ /ns.*[1-9]/
      system "~/bin/sndplay ~/Library/autotest/bonk.wav -volume 0.5" 
      growl "Test Results", "#{output}", '~/Library/autotest/rails_fail.png', 2 #, "-s" 
    else
      system "~/bin/sndplay ~/Library/autotest/om.aiff -volume 0.1"    
      growl "Test Results", "#{output}", '~/Library/autotest/rails_ok.png'
    end
  end
end

1/29/08 UPDATE: The autotest API has been updated to have sound playback hooks… examples here.

1 Response to “Adding sound to your .autotest”

  1. Eloy Duran Says:

    Hi David,

    Thanks for the nice snippet! But I just wanted to let you know that the code on line 9 should nowadays be (which you might already have known):

    at.results.to_s.slice(/(\d+).*errors/)

    Since the results method returns an array.

    Cheers, Eloy

Leave a Reply