Sha256: 24b8c47dbc298546b01b51b0082b5aa101d3bea43303be68c83d505c1a15b620

Contents?: true

Size: 1.91 KB

Versions: 2

Compression:

Stored size: 1.91 KB

Contents

require 'libnotify'

module Minitest
  module Libnotify
    class Notifier
      DEFAULT_OPTIONS = {
        :global => {
          :timeout      => 2.5,
          :append       => false,
          :description  => proc { [ defined?(RUBY_ENGINE) ? RUBY_ENGINE : "ruby", RUBY_VERSION ].join(" ") },
        },

        :pass => {
          :description  => proc { |description| "Tests PASSED #{description}" },
          :urgency      => :critical,
          :icon_path    => "face-laugh.*"
        },

        :fail => {
          :description  => proc { |description| "Tests FAILED #{description}" },
          :urgency    => :critical,
          :icon_path  => "face-angry.*"
        }
      }

      def initialize
        # TODO: Write a public interface where the options can be modified (custom icon_path, description etc)
        @options = DEFAULT_OPTIONS
      end

      def notify(stats, state)
        body =  "#{stats[:assertions]} assertions, "
        body << "#{stats[:failures]} failures, "
        body << "#{stats[:errors]} errors, "
        body << "#{stats[:skips]} skips"

        default_description = config_for(:description)
        libnotify.body      = config_for(:body, state, body)
        libnotify.summary   = config_for(:description, state, default_description)
        libnotify.urgency   = config_for(:urgency, state)
        libnotify.icon_path = config_for(:icon_path, state)
        libnotify.show!
      end

    private

      def libnotify # :nodoc:
        if @libnotify.nil?
          @libnotify = ::Libnotify.new(:timeout => config_for(:timeout), :append => config_for(:append))
        end

        @libnotify
      end

      def config_for(name, state=:global, default=nil) # :nodoc:
        value = @options[state][name] || @options[:global][name]
        if value.respond_to?(:call)
          value.call(default)
        else
          value.nil? ? default : value
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
minitest5-libnotify-0.0.2 lib/minitest/libnotify/notifier.rb
minitest5-libnotify-0.0.1 lib/minitest/libnotify/notifier.rb