Autotest Growling in Red & Green

Here is a quick scenario.. You have over 200 tests and 800 assertions for your Rails application and you always run them before every subversion commit, but because you love tests so much or maybe you’re doing some TDD you want these tests to be running all the time.

You need ZenTest and its beautiful autotest, which will not only keep your test running but it will do it in a very clever way. autotest keeps an eye on all your code changes, once you change a file it will run its according tests only, instead of running the whole bundle.

sudo gem install ZenTest

So now we have a wonderful tool, let’s pimp it with some colors, how about red for fails and green for passes? Thanks to Pat Eyler and his cute Red and Green for Ruby gem that does the this for us:

sudo gem install --remote Redgreen

Now let’s make this pimped ride growl. If you are on Mac then you probably know about Growl so why don’t we use growlnotify to notify us with autotest results? Download and install Growl in case you don’t have it and then install growlnotify:

“In your shell, cd to the directory on the Growl disk image containing growlnotify, and type ./install.sh. That script will install growlnotify to /usr/local/bin and the manpage to /usr/local/man.” from Growl documentation

Getting too much growl notification can get very nasty with every test running for every code change, the best solution for this is to popup a growl autotest notifier when and only when we have new test result, in other words, if any of my tests fails I should be notified, if they pass again I should also be notified, now as long as my tests are passing I don’t need to be notified anymore, right?

We’ll add a light file to our home directory named .autotest with all these configurations we talked about, in addition to all the above let’s have a colored Rails icon for each red/green test notification too.

Error: Could not open autotest.rb

Just place the following Rails icons in your home directory along with the .autotest file, run autotest -rails and enjoy being notified, Happy Hacking.

Rails Red
Rails Green

Update: In case you don’t really care about having the rails icons you can make your .autotest file way simpler (Thanks to Ryan’s comment) by requiring autotest/redgreen and autotest/growl and you are all set.

Error: Could not open autotest_without_icons.rb

Additional Resources:

Here are a couple of other resources from where I collected the solution I have here:

Comments

7

  1. ryan davis said..

    why? your .autotest could simply read:

    require ‘autotest/redgreen’
    require ‘autotest/growl’

    I don’t see much of anything that is added, except for the complexity. If something is added, I’d prefer to see a patch submitted, not a blog post I have to search for.

  2. Rida said..

    Hello Ryan,

    Thank you for commenting here on ridaalbarazi.com, your comment is completely valid, I had some outdated information on how to customize autotest from different blogs that I linked to here. Although I could have known about that if there is enough documentation for autotest on your website.

    The value I’m trying to add here is to offer some tips and tricks to Rails developers, I didn’t intend to patch or add value to autotest itself.

  3. MEZYAN said..

    Hi Reda,
    From what I see it is very impressive, all I can say, carry on , with God’s blessing, hopping that I can understand something.

  4. Ahmad said..

    Hi Rida,
    Very nice website, and impressive too, keep going and I wish you luck.

  5. David Lowenfels said..

    Hi Rida,
    thanks for giving me credit for the images! :)

  6. Complete And Utter Rails Bliss | Mornography UK said..

    [...] autotest is part of the ZenTest package. It will automatically and continuously run your Rails tests every time you modify a file (and it will always just run the tests for the part off your app you’ve changed). When you’re on OS X, spice it up with Growl notifications. Together with the Shoulda plugin mentioned above, writing tests has become fun again. [...]

  7. 15 Top Tools for a Rails Programmer | Cheer Factory - Technology, Outdoor and Design said..

    [...] 8. Zentest:”http://www.zenspider.com/ZSS/Products/ZenTest/” especially autotest which runs your tests automatically each time you save a relevant file. Linking in the Growl notifications You might also want to get this working with Rspec. If you do then.. this might be of interest. [...]

Leave a Reply

you can use these xhtml tags:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Articles Permanent Link