Sha256: f3818d1eeb79864684bcc8649e16d58b82d18b0aeb7b9e7785bf8d9070ce92c7

Contents?: true

Size: 1.25 KB

Versions: 5

Compression:

Stored size: 1.25 KB

Contents

# Base class for all specific notifiers.
#
# Each notifier should implement +notify+ and +usable?+.
#
# Note: Base is NOT usable.
module RiotNotifier

  class Base < ::Riot::DotMatrixReporter

    def initialize(*args, &block)
      raise "#{self.class} is NOT usable" unless self.class.usable?
      super
    end

    # Notifies you about failures and errors.
    # This methods should be overridden in order to define specific notifications libraries.
    def notify(color, msg)
      # override me
    end

    # Tests if this notifier is usable.
    # Should contain some initialization code e.g. require 'libnotify'.
    def self.usable?
      # override
      false
    end

    def self.inherited(notifier)
      ::RiotNotifier.register notifier
    end

    # Override

    def fail(desc, message, file, line)
      super
      notify(:red, "FAILURE: #{message}@#{file}:#{line}")
    end

    def error(desc, error)
      super
      notify(:red, "ERROR: #{error}")
    end

    def results(time_taken)
      super
      unless bad_results?
        notify(:green, "%d passes, %d failures, %d errors in %s seconds" % [passes, failures, errors, ("%0.6f" % time_taken)])
      end
    end

  private

    def bad_results?
      failures + errors > 0
    end

  end

end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
riot_notifier-0.5.0 lib/riot_notifier/base.rb
riot_notifier-0.4.0 lib/riot_notifier/base.rb
riot_notifier-0.3.0 lib/riot_notifier/base.rb
riot_notifier-0.2.0 lib/riot_notifier/base.rb
riot_notifier-0.1.1 lib/riot_notifier/base.rb