home icon contact icon rss icon

Autotest and KNotify

I’ve configured KNotify to work with ZenTest. To see knotify messages just drop below code to ~/.autotest


module KDENotify
 def self.span str, color
   "<span style=\"color: #{color}\">#{str}</span>" 
 end

 def self.notify title, msg, color
   system "dcop knotify default notify " +
          "eventname '#{span(title, color)}' '#{span(msg, color)}' '' '' 16 2" 
   end

 Autotest.add_hook :ran_command do |at|
   if at.results.split("\n").last.first =~ /([0-9]+\sexamples,\s([0-9]+)\sfailures?(,\s([0-9]+) pending)?)/
     message, failures, pending = $1, $2.to_i, $4.to_i
     if failures > 0
       notify "Tests failed", message, "darkred" 
     elsif pending > 0
       notify "Tests passed with some tests pending", message, "goldenrod" 
     else
       notify "Tests passed", message, "darkgreen" 
     end
   end
 end
end

Leave a Comment