Post Meta

Bookmarks

  • Delicious
  • Digg
  • Reddit
  • Magnolia
  • Newsvine
  • Furl
  • Facebook
  • Technorati

Finally I have a good and simple script for Autotest RSpec to notify on any errors in my code .


Today I have installed the latest RSpec (1.1.8) and Autotest (3.4.0) to my Rails (2.1.1) and all seems to be fine, easy to install. I’m using Gnome and wanted to add the simplest notification to my UI.

I’ve found many notification snippets, but none was complete. One was notifying me about spec execution success or failure, the other sent notifications when an error (ie. a syntax error) occurred in my code during spec execution.

I’ve combined these three events into one .autotest snippet:

require 'autotest/redgreen'
require 'autotest/timestamp'
 
module Autotest::GnomeNotify
  def self.notify title, msg, img
    system "notify-send '#{title}' '#{msg}' -i #{img} -t 2000"
  end
 
  Autotest.add_hook :ran_command do |at|
    image_root = "~/.autotest_images"
    r = results = [at.results].flatten.join("\n")
    results.gsub!(/\\e\[\d+m/,'')
    output = results.slice(/(\d+)\sexamples?,\s(\d+)\sfailures?/)
    puts output.inspect
    if output
      if $~[2].to_i > 0
        notify "FAIL", "#{output}", "#{image_root}/fail.png"
      else
        notify "Pass", "#{output}", "#{image_root}/pass.png"
      end
    else
    	notify "FAIL", "You must have a non-rspec error in your code.\n Check the autotest log for details.", "#{image_root}/fail.png"
    end
  end
 
end


Related Post

  • No Related Post

Leave A Comment

+ -