Autotest: Now, With Sound Effects! 21 Comments

Jul 28, 2007

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 mpg321
for 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)

Comments

Leave a response

  1. jerry richardsonJuly 31, 2007 @ 08:33 PM

    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?

  2. fozJuly 31, 2007 @ 08:44 PM

    You probably have an older version of ports, try ‘sudo port selfupdate’ and see if that fixes it…

  3. johnJuly 31, 2007 @ 09:51 PM

    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
    end
    

    And then a few additions in the .autotest file.

      Autotest::Sound.process_devnull = "> c:/Windows/Temp/_mplayer_tmp.txt" 
      Autotest::Sound.process_bg = "" 
    

    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:

    http://www.mplayerhq.hu/design7/dload.html

    And have this line my .autotest file:

     Autotest::Sound.sound_app = "call c:/mplayer/mplayer.exe -really-quiet"

    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.

  4. Jamie FlournoyJuly 31, 2007 @ 11:08 PM

    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.

  5. fozJuly 31, 2007 @ 11:59 PM

    John, thanks for getting this working on Windows! I incorporated your changes back into the release.

    Jamie, thanks for catching that bug, instructions updated!

  6. Matt AimonettiAugust 01, 2007 @ 10:28 AM

    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

    require '~/autotest/sound/sound.rb'
  7. jinjingAugust 01, 2007 @ 12:49 PM

    Tip For fink users

    “mpg321” is probably not in the default tree, try “madplay” :D

    Thanks for the plugin foz, love it !

  8. fozAugust 01, 2007 @ 05:32 PM

    @matt: Agh! sound.rb was in the right place, the instructions were wrong! Fixed…

  9. Don ParishAugust 02, 2007 @ 12:10 AM

    Thanks, I just got it working in Windows using the instructions in the updated ZIP file, and the mplayer program.

  10. Bala ParanjAugust 05, 2007 @ 12:47 AM

    I installed this on my Mac. The sound is the same whether the test fails or passes. Is it supposed to be different?

  11. fozAugust 06, 2007 @ 02:45 AM

    @Bala: The sounds are definitely supposed to be different… make sure you have the latest ZenTest gem installed?

  12. David LowenfelsAugust 07, 2007 @ 04:06 AM

    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.

  13. topfunkyAugust 11, 2007 @ 08:05 AM

    I think we need a recording of Ryan Davis saying “FAIL!” and “Pass” for the audio.

    I’ll try to acquire that.

  14. Priit TamboomAugust 13, 2007 @ 09:27 AM

    Thanks for sound!

    I’m getting “pass” sound when there is actually SyntaxError. It looks like a bug?

  15. zuwikiAugust 18, 2007 @ 08:24 PM

    That’s pretty sweet. And I thought autotest was fun before! :D

    That recording of Ryan Davis would make it even more awesome.

  16. masoneMarch 15, 2008 @ 08:31 AM

    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 :)

  17. masoneMarch 15, 2008 @ 08:56 AM

    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

  18. Ken CollinsApril 06, 2008 @ 11:12 PM

    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

  19. fozApril 09, 2008 @ 10:31 PM

    @Ken – awesome!!! I’m honored and inspired that you took it to the next level :)

  20. Jamie FlournoyMay 18, 2008 @ 06:52 AM

    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|
  21. Ryan DavisMay 20, 2008 @ 12:51 AM

    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.

Comment