Module: Autotest::Growl

Defined in:
lib/autotest-mac.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.growl(title, message, color, priority = 0, stick = "") ⇒ Object

Display a message through Growl.



20
21
22
23
# File 'lib/autotest-mac.rb', line 20

def self.growl title, message, color, priority=0, stick=""
  icon = File.join(GEM_DIR, 'img', "ruby_#{color}.png")
  system "growlnotify -H localhost -n autotest --image '#{icon}' -p #{priority} -m #{message.inspect} '#{title}' #{stick}"
end

Instance Method Details

#ran_commandObject

Parse the test results and send them to Growl.



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/autotest-mac.rb', line 36

Autotest.add_hook :ran_command do |autotest|
  gist = autotest.results.grep(/\d+\s+(example|test)s?/).map {|s| s.gsub(/(\e.*?m|\n)/, '') }.join(" / ")
  if gist == ''
    growl "#{@label} cannot run tests", '', 'grey'
  else
    if gist =~ /[1-9]\d*\s+(failure|error)/
      growl "#{@label} fails some tests", "#{gist}", 'red'
    elsif gist =~ /pending/
      growl "#{@label} has pending tests", "#{gist}", 'yellow'
      @run_scenarios = true
    else
      growl "#{@label} passes all tests", "#{gist}", 'green'
      @run_scenarios = true
    end
  end
end

#run_commandObject

Set the label and clear the terminal.



27
28
29
30
31
32
# File 'lib/autotest-mac.rb', line 27

Autotest.add_hook :run_command do
  @label = File.basename(Dir.pwd).upcase
  @run_scenarios = false
  print "\n"*2 + '-'*80 + "\n"*2
  print "\e[2J\e[f"   # clear the terminal
end