Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Apr 29th, 2012  |  syntax: None  |  size: 1.20 KB  |  hits: 21  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. class Growl
  2.  
  3.   attr_accessor :report, :status
  4.  
  5.   def initialize(report, opts = {})
  6.     @report, options = report, create_options(opts)
  7.     message = create_message
  8.    
  9.     opts = options.inject([]) do |arr, item|
  10.       key, value = item.first, item.last
  11.       (value.is_a?(Hash) ? arr.push("--#{key} '#{value[@status]}'") : arr.push("--#{key} '#{value}'"); arr;)
  12.     end
  13.  
  14.     notifier = `which growlnotify`.chomp
  15.     opts.unshift("-w -n RSpec")
  16.     system %(#{notifier} #{opts.join(' ')} -m \"#{message}\" &)
  17.    
  18.   end
  19.  
  20.   private
  21.  
  22.   def create_message
  23.     examples = @report.instance_variable_get(:@example_count).to_i
  24.     failures = @report.instance_variable_get(:@failure_count).to_i
  25.     pendings = @report.instance_variable_get(:@pending_count).to_i
  26.     duration = @report.instance_variable_get(:@duration)
  27.     @status  = (failures == 0) ? :pass : :fail
  28.     "#{examples} Examples - #{failures} Failures - #{pendings} Pending"
  29.   end
  30.  
  31.   def create_options(opts)
  32.     {:title     => "Test Results",
  33.      :image     => {:pass => File.expand_path('~/.watchr_images/passed.png'), :fail => File.expand_path('~/.watchr_images/failed.png')},
  34.      :priority  => {:pass => 0, :fail => 2}    
  35.      }.merge!(opts)
  36.   end
  37.  
  38.  
  39. end