Sha256: bccb58037bb0488642607f31e5f591e811bf70da697a7d4c47661ec6c21b40cc

Contents?: true

Size: 1.84 KB

Versions: 1

Compression:

Stored size: 1.84 KB

Contents

require 'net/snarl'
require 'autotest/results_parser'

class Autotest
  module Snarl
    IMG_PATH = File.expand_path(File.join(File.dirname(__FILE__), '..' , '..', 'img'))

    Autotest.add_hook :run_command do
      @project = File.basename(Dir.pwd)
    end

    Autotest.add_hook :ran_command do |autotest|
      unless @ran_tests
        results = Autotest::ResultsParser.new(autotest)
        if results.exists?
          case results.framework
          when 'rspec'
            if results.has?('example-failed')
              notify "#{@project}: some examples failed.",
                      "#{results['example-failed']} of #{results.get('example')} failed",
                      'failed'
            elsif results.has?('example-pending')
              notify "#{@project}: some examples are pending.",
                      "#{results['example-pending']} of #{results.get('example')} pending",
                      'pending'
            else
              notify "#{@project}: all examples passed.",
                      "#{results.get('example')}",
                      'passed'
            end
          end
        else
          notify "#{@project}: Could not run tests.", '', 'error', true
        end
        false
      end
    end

    def self.notify(title, text, klass, sticky = false)
      snarl.notify(
        :app => 'autotest',
        :title => title,
        :text => text,
        :class => klass,
        :timeout => sticky ? 0 : 5,
        :icon => File.join(IMG_PATH, "#{klass}.png")
      )
    end

    def self.snarl
      return @@snarl if defined?(@@snarl)

      @@snarl = Net::Snarl.new
      @@snarl.register('autotest')
      @@snarl.add_class('autotest', 'passed')
      @@snarl.add_class('autotest', 'failed')
      @@snarl.add_class('autotest', 'pending')
      @@snarl.add_class('autotest', 'error')
      @@snarl
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
autotest-snarl-0.0.2 lib/autotest/snarl.rb