Sha256: 97953d50051b3b1d59cb6a306c78b6d8cba7f778d29f5875244ff2be545acb6f

Contents?: true

Size: 1.46 KB

Versions: 1

Compression:

Stored size: 1.46 KB

Contents

$:.unshift File.dirname(__FILE__)

require 'snarl' if RUBY_PLATFORM =~ /mswin/
require 'test/unit/ui/console/testrunner'

module Test
  module Unit
    module UI
      module Console
        class TestRunner
          alias finished_original finished
          
          def finished(elapsed_time)
            finished_original(elapsed_time)
            matches, *output = *@result.to_s.match(/(\d+)\stests,\s(\d+)\sassertions,\s(\d+)\sfailures,\s(\d+)\serrors/)
            
            output = output.map {|i| i.to_i }
            t, a, f, e = output
            
            if f > 0 || e > 0
              # test has failed or raised an error
              title = "FAIL"
              image = e > 0 ? "error.png" : "failure.png"
            elsif a > 0
              # everything's ok
              title = "Passed"
              image = "passed.png"
            else
              # no assertions
              return
            end
            
            image = File.join(File.dirname(__FILE__), "test_notifier", "icons", image)
            
            if RUBY_PLATFORM =~ /darwin/
              system("growlnotify -n test_notifier --image #{img} -p 2 -m #{@result.to_s} #{title}")
            elsif RUBY_PLATFORM =~ /mswin/
              Snarl.show_message(title, @result.to_s, image)
            elsif RUBY_PLATFORM =~ /linux/
              system("notify-send -i #{image} #{title} \"#{@result.to_s}\"")
            end
          end
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
test_notifier-0.0.1 lib/test_notifier.rb