Update April 9, 2008: Ken Collins has released a new version of the sound plugin with playlist support!
We’ve all been enjoying autotest, part of the ZenTest gem. If you’ve tricked out your kit, then you have plugins configured, so at minimum you’re red, green and growling. Now, things get really fun.
Watch a screencast of autotest running with sound effects
I’m stoked to announce the sound plugin for autotest. This simple chunk of code will fire off sounds for different events in autotest. I’ve provided a set of custom-made sounds, produced with my trusty Nord Modular synthesizer and fine-tuned for an optimal testing experience. You should be able to use these all day without annoying your neighbors too much.
Here’s what you need to do:
1. Install mgp321
in OS X:$ sudo port install mpg321for Linux:
$ sudo apt-get install mpg321
2. Download and extract the plugin
The starter sound fx are in the zip file. Extract it in your home directory, it will create ~/autotest/sound.
autotest-sound-1_2.zip (86k)
3. Configure your ~/.autotest file:
require '~/autotest/sound/sound.rb' Autotest::Sound.sound_path = "~/autotest/sound/sound_fx/"
Enjoy TDD with audio feedback!
I’ve been using this setup for several weeks now. I initially wrote it as a gag, but I have since found it to be incredibly useful. It’s nice know what your testing status via audio – you don’t have to switch windows or take your eyes off the code. I’ve even turned off Growl, I don’t need it any more. audio makes testing more fun. :)
If there are any problems or feedback, please post a comment here.
UPDATE:Plugin instructions and zip file updated, now with Windows support. Thanks, John and Jamie.
UPDATE #2:Fixed bad path in instructions and doc fixes in zip file. (thanks, Matt)




i tried the port command is osx and got the error messsage: Error: Unable to execute port: invalid command name “configure.universal_args”
Is that something you ran into during your development?
You probably have an older version of ports, try ‘sudo port selfupdate’ and see if that fixes it…
Hi Foz,
This is great, though it doesn’t quite work out of the box in Windows. What helped was a few more configuration options in the sound.rb file.module Autotest::Sound @@sound_path = '' @@sound_app = 'mpg321' @@process_devnull = '> /dev/null 2>&1' @@process_bg = '&' def self.sound_path= o @@sound_path = o end def self.sound_app= o @@sound_app = o end def self.process_devnull= o @@process_devnull = o end def self.process_bg= o @@process_bg = o end def self.playsound file cmd = "#{@@sound_app} #{@@sound_path + file} #{@@process_devnull} #{@@process_bg}" # puts cmd system cmd end [:run, :red, :green, :quit, :run_command, :ran_command].each do |hook| Autotest.add_hook hook do |at| playsound "#{hook.to_s}.mp3" unless $TESTING end end endAnd then a few additions in the .autotest file.
Lastly, for Windows users looking for a command line audio player, I’m using mplayer, which is doing nicely for this job. I found it here:
And have this line my .autotest file:
I believe that this preserves your original behavior in OS/X, but I wasn’t able to test it. It does work in my system. Thanks for putting this together.
Cool! One note: your config instructions on this page don’t match the zip file layout:
Autotest::Sound.sound_path = “/autotest/sound_fx/”
should be: Autotest::Sound.sound_path = “/autotest/sound/sound_fx/”
Cuz the zip file has the sound_fx dir inside autotest/sound.
John, thanks for getting this working on Windows! I incorporated your changes back into the release.
Jamie, thanks for catching that bug, instructions updated!
Cool stuff, not that with the latest package the sound.rb file is in the wrong directory. So. or you move it one level up, or you change your .autotest code to
Tip For fink users
“mpg321” is probably not in the default tree, try “madplay” :D
Thanks for the plugin foz, love it !
@matt: Agh! sound.rb was in the right place, the instructions were wrong! Fixed…
Thanks, I just got it working in Windows using the instructions in the updated ZIP file, and the mplayer program.
I installed this on my Mac. The sound is the same whether the test fails or passes. Is it supposed to be different?
@Bala: The sounds are definitely supposed to be different… make sure you have the latest ZenTest gem installed?
I had this idea last year… http://blog.internautdesign.com/2006/12/18/adding-sound-to-your-autotest
but it’s nice to have extra stuff like a sound every time autotest (re)starts your sounds are cool too. I love synthesizers.. used to program audio DSP before I got into ruby/rails.
I think we need a recording of Ryan Davis saying “FAIL!” and “Pass” for the audio.
I’ll try to acquire that.
Thanks for sound!
I’m getting “pass” sound when there is actually SyntaxError. It looks like a bug?
That’s pretty sweet. And I thought autotest was fun before! :D
That recording of Ryan Davis would make it even more awesome.
I have the same problem as Priit. It worked great when I installed it, but suddenly it started playing the wrong sound. I’ll get the pass sound even when something went bad.
Maybe it’s because I somewhen updated the Zentest gem or rspec? I’m really missing the benefit of your script I had. It would be great if there were a solution!
Thanks :)
Got it. rspec_on_rails 1.1.3 was the culprit. Installing 1.1.4 from the trunk solves the problem.
See: http://rspec.lighthouseapp.com/projects/5645/tickets/279-autotest-never-calls-the-red-hook
Thanks for the idea… just wanted you to know I put together a total rework of your autotest sounds. In my version I have the ability to linearly loop thru a red/green playlist.
http://www.metaskills.net/2008/4/6/autotest-playlist-for-red-green-feedback
@Ken – awesome!!! I’m honored and inspired that you took it to the next level :)
Probably obvious but this might as well make it into the distributed code…
To get rid of the complaint from Autotest about the deprecated :run hook, change :run to :initialize in sound.rb and rename your run.mp3 sound to initialize.mp3.29c29 < [:run, :red, :green, :quit, :run_command, :ran_command].each do |hook| --- > [:initialize, :red, :green, :quit, :run_command, :ran_command].each do |hook|I’m adding Autotest::ALL_HOOKS to the next release to make it easier for you to stay up to date with the hook list.
cool topic .. really helpful !!