You're at Mabishu, a website about discovering quality on code, searching emerging technologies, and leading a simpler, more mindful coder life. This site was established in 2005 by Fran Diéguez, a blogger, software developer, and open source geek. Subscribe to the RSS feed for updates.

Autotest con advertencias en Growl

Written on May 7th, 2008
.

He buscado en la red un método para “enganchar” la utilidad de testeo Autotest en Ruby y el sistema de mensajes de sistema Growl en Mac OS X y la verdad es que no me fue muy bien.
Una vez modificado el archivo .autotest en mi $home ya funciona a la perfección. Relato a continuación como obtener esta maravilla.
Basta instalar Growl en Mac OS tal que así:

wget http://growl.info/files/Growl-1.1.2.dmg
open Growl-1.1.2.dmg
cd /Volumes/Growl\ 1.1.2/Extras/growlnotify
less install.sh
sudo ./install.sh
cd
hdiutil detach /Volumes/Growl\ 1.1.2

y luego descargarte un par de imágenes para hacer los mensajes un poco más bonitos

cd ~
wget http://blog.internautdesign.com/files/rails_fail.png
wget http://blog.internautdesign.com/files/rails_ok.png
mkdir -p Pictures/Rails_Growl/
mv rails_fail.png Pictures/Rails_Growl/rails_fail.png
mv rails_ok.png Pictures/Rails_Growl/rails_ok.png

luego se edita el fichero .autotest que he modificado un poquillo

require 'autotest/redgreen'
require 'autotest/html_report'
require 'autotest/menu'
module Autotest::Growl

  def self.growl msg, options={}
    salida = "growlnotify -n autotest --image \"#{options[:img]}\"
                   -p #{options[:pri]} -d #{rand(100)} -m \"#{msg}\" \"Tests\" #{options[:sticky]}"
    system salida
  end

  Autotest.add_hook :ran_command do |at|
    results = [at.results].flatten.join("\n")
    output = results.slice(/(\d+)\s+assertions?,\s*(\d+)\s+failures?,\s*(\d+)\s+errors?/)
    failures = $~[3].to_i + $~[2].to_i
    options = (failures > 0)? {:img=>"/Users/#{ENV["USER"]}/Pictures/Rails/fail.png",
                                            :pri => 0, :sticky => "" } :
                                           { :img => "/Users/#{ENV["USER"]}/Pictures/Rails/ok.png",
                                             :pri => 0,:sticky => "" }
    output = output.gsub(/assertions/, "aserciones").gsub(/failures/, "fallos").gsub(/errors/, "errores")
    if output
      growl "#{output}", options
    end
  end
end

y listo ya podemos correr test en apps ruby y que se nos notifique en growl

Autotest con Growl

Might be interested on:

Comments

  1. [...] Fuente: Mabishu [...]

    # Emili Parreño » Blog Archive » Autotest con Growl ,
    Write on November 19th, 2008 at 10:59 pm

Leave a Response