Growl + Autotest Rails with Zentest 3.4.0

Posted by labrat

Yes, I know this is like the millionth post on the same subject in a span of days. I promise that this will be my last one on ZenTest + Growl for a while. I noticed that with ZenTest 3.4.0, not all the Growl notifications were producing output. That kinda sucks. Plus the default has way too many notices. One for if autotest runs, one for restarting, one for success, one for failure, etc. You get the idea. I'm already swimming in all the distractions you could handle with RSS, chat, email, and whatever. Plus, I really don't care about the process of autotest running, only the results. I figured, all I really need to see is the final output: fakeleopard.jpg I want the text to be red and the message to be sticky if it fails as well. So I peeked around the libraries and came up with the following alternative for the .autotest file: module Autotest::Growl def self.growl title, msg, pri=0, stick="" system "growlnotify -n autotest --image /location_of/rails.png -p #{pri} -m #{msg.inspect} #{title} #{stick}" end Autotest.add_hook :ran_command do |at| output = at.results.slice(/(\d+).*errors/) if output =~ /ns.*[1-9]/ growl "Test Results", "#{output}", 2, "-s" else growl "Test Results", "#{output}" end end end It's pretty self explanatory. It basically slices out the final results line, checks to see if errors or failures are greater than one and make error notices sticky and red (using the priority flag & Growl preferences). Be sure to comment out "require 'autotest/growl'" if you already have that in .autotest. Now, you only get one bubble per run and the notice stays sticky if the tests fail. Of course, if all you want are results you can reduce the middle block with (getting rid of the "-s" in the example above will give you a non-sticky version too): output = at.results.slice(/(\d+).*errors/) growl "Test Results", "#{output}" Now you can really keep those tests in the background and focus on coding!
Comments

Leave a response

  1. ArthurGeekMarch 23, 2007 @ 08:05 PM

    This is not working for me..

    I’m getting:

    /Users/arthur/.autotest:16: undefined method growl’ for main:Object (NoMethodError) from /usr/local/lib/ruby/gems/1.8/gems/ZenTest-3.4.3/lib/autotest.rb:283:in[]’ from /usr/local/lib/ruby/gems/1.8/gems/ZenTest-3.4.3/lib/autotest.rb:283:in hook’ from /usr/local/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:ininject’ from /usr/local/lib/ruby/gems/1.8/gems/ZenTest-3.4.3/lib/autotest.rb:282:in each’ from /usr/local/lib/ruby/gems/1.8/gems/ZenTest-3.4.3/lib/autotest.rb:282:ininject’ from /usr/local/lib/ruby/gems/1.8/gems/ZenTest-3.4.3/lib/autotest.rb:282:in hook’ from /usr/local/lib/ruby/gems/1.8/gems/ZenTest-3.4.3/lib/autotest.rb:112:inrun_tests’ from /usr/local/lib/ruby/gems/1.8/gems/ZenTest-3.4.3/lib/autotest.rb:100:in get_to_green’ from /usr/local/lib/ruby/gems/1.8/gems/ZenTest-3.4.3/lib/autotest.rb:84:inrun’ from /usr/local/lib/ruby/gems/1.8/gems/ZenTest-3.4.3/lib/autotest.rb:82:in loop’ from /usr/local/lib/ruby/gems/1.8/gems/ZenTest-3.4.3/lib/autotest.rb:82:inrun’ from /usr/local/lib/ruby/gems/1.8/gems/ZenTest-3.4.3/lib/autotest.rb:62:in run’ from /usr/local/lib/ruby/gems/1.8/gems/ZenTest-3.4.3/bin/autotest:45 from /usr/local/bin/autotest:16:inload’ from /usr/local/bin/autotest:16

  2. ArthurGeekMarch 23, 2007 @ 08:30 PM

    Nah…

    I get it to rum now, but it’s always showing: 0 Errors.

    If I get a lot of failures, I get the 0 Errors message too..

  3. labrat March 23, 2007 @ 09:02 PM

    Did you uncomment the following lines in the “.autotest” file?:

    require ‘autotest/redgreen’ require ‘autotest/timestamp’

    If they’re missing please add them. I don’t know what to say. that’s exactly how I have it in my settings.

  4. thomas kernJune 24, 2007 @ 01:12 AM

    hi jabrat, quick question about your screenshots, what are all the icons in the topbar if i may ask? esp. the three on the left

    cheers thomas

Comment