Return to Snippet

Revision: 5556
at March 15, 2008 13:39 by peleteiro


Updated Code
require 'autotest/redgreen'

# You need mpg321, so:
# sudo port install mpg321

# Resources from:
#  http://www.thelucid.com/articles/2007/07/30/autotest-growl-fail-pass-smilies
#  http://www.fozworks.com/2007/7/28/autotest-sound-effects

module Autotest::Growl

  def self.growl(title, msg, type)
    pri = {
      :fail => 2,
      :pending => 1,
      :pass => 0
    }
    system "growlnotify --name Autotest --image ~/.autotest_resources/#{type}.png --title #{title.inspect} --message #{msg.inspect} --priority #{pri[type]}"
  end

  Autotest.add_hook :ran_command do |autotest|
    results = [autotest.results].flatten.join("\n")
    output = results.slice(/(\d+)\s+examples?,\s*(\d+)\s+failures?(,\s*(\d+)\s+pending)?/) 
    if output  =~ /[1-9]\sfailures?/
      growl "FAIL", "#{output}", :fail
    elsif output  =~ /[1-9]\spending?/
      growl "PENDING", "#{output}", :pending
    else
      growl "PASS", "#{output}", :pass
    end
  end
end

module Autotest::Sound  
  def self.play_sound sound
    system "mpg321 ~/.autotest_resources/#{sound}.mp3 > /dev/null 2>&1 &"
  end

  Autotest.add_hook :ran_command do |autotest|
    results = [autotest.results].flatten.join("\n")
    output = results.slice(/(\d+)\s+examples?,\s*(\d+)\s+failures?(,\s*(\d+)\s+pending)?/) 
    if output  =~ /[1-9]\sfailures?/
      play_sound :fail
    elsif output  =~ /[1-9]\spending?/
      play_sound :pending
    else
      play_sound :pass
    end
  end
end

Revision: 5555
at March 15, 2008 11:43 by peleteiro


Updated Code
require 'autotest/redgreen'

# You need mpg321, so:
# sudo port install mpg321

# Resources from:
#  http://www.thelucid.com/articles/2007/07/30/autotest-growl-fail-pass-smilies
#  http://www.fozworks.com/2007/7/28/autotest-sound-effects

module Autotest::Growl

  def self.growl(title, msg, img)
    system "growlnotify -n autotest --image ~/.autotest_resources/#{img}.png -m #{msg.inspect} #{title}"
  end

  Autotest.add_hook :ran_command do |autotest|
    results = [autotest.results].flatten.join("\n")
    output = results.slice(/(\d+)\s+examples?,\s*(\d+)\s+failures?(,\s*(\d+)\s+pending)?/) 
    if output  =~ /[1-9]\sfailures?/
      growl "FAIL", "#{output}", :fail
    elsif output  =~ /[1-9]\spending?/
      growl "PENDING", "#{output}", :pending
    else
      growl "PASS", "#{output}", :pass
    end
  end
end

module Autotest::Sound  
  def self.play_sound(sound)
    system "mpg321 ~/.autotest_resources/#{sound}.mp3 > /dev/null 2>&1 &"
  end

  Autotest.add_hook :ran_command do |autotest|
    results = [autotest.results].flatten.join("\n")
    output = results.slice(/(\d+)\s+examples?,\s*(\d+)\s+failures?(,\s*(\d+)\s+pending)?/) 
    if output  =~ /[1-9]\sfailures?/
      play_sound :fail
    elsif output  =~ /[1-9]\spending?/
      play_sound :pending
    else
      play_sound :pass
    end
  end
end

Revision: 5554
at March 15, 2008 11:42 by peleteiro


Initial Code
require 'autotest/redgreen'

# You need mpg321, so:
# sudo port install mpg321

# Resources from:
#  http://www.thelucid.com/articles/2007/07/30/autotest-growl-fail-pass-smilies
#  http://www.fozworks.com/2007/7/28/autotest-sound-effects

module Autotest::Growl

  def self.growl(title, msg, img)
    system "growlnotify -n autotest --image ~/.autotest_resources/#{img}.png -m #{msg.inspect} #{title}"
  end

  Autotest.add_hook :ran_command do |autotest|
    results = [autotest.results].flatten.join("\n")
    output = results.slice(/(\d+)\s+examples?,\s*(\d+)\s+failures?(,\s*(\d+)\s+pending)?/) 
    if output  =~ /[1-9]\sfailures?/
      growl "FAIL", "#{output}", :fail
    elsif output  =~ /[1-9]\spending?/
      growl "PENDING", "#{output}", :pending
    else
      growl "PASS", "#{output}", :pass
    end
  end
end

module Autotest::Sound  
  def self.play_sound sound
    system "mpg321 ~/.autotest_resources/#{sound}.mp3 > /dev/null 2>&1 &"
  end

  Autotest.add_hook :ran_command do |autotest|
    results = [autotest.results].flatten.join("\n")
    output = results.slice(/(\d+)\s+examples?,\s*(\d+)\s+failures?(,\s*(\d+)\s+pending)?/) 
    if output  =~ /[1-9]\sfailures?/
      play_sound :fail
    elsif output  =~ /[1-9]\spending?/
      play_sound :pending
    else
      play_sound :pass
    end
  end
end

Initial URL

                                

Initial Description

                                

Initial Title
My .autotest file

Initial Tags

                                

Initial Language
Ruby