Sha256: 3d8b98c8e19a00367613952fe1c94cfabe7286bf996499dfd9591d6c2e2c9b5e

Contents?: true

Size: 1.36 KB

Versions: 14

Compression:

Stored size: 1.36 KB

Contents

module Guard
  class RSpec < Plugin
    class Notifier
      attr_accessor :options

      def initialize(options = {})
        @options = options
      end

      def notify(summary)
        return unless options[:notification]
        failure_count, pending_count = _parse_summary(summary)
        image = _image(failure_count, pending_count)
        priority = _priority(image)
        Guard::Compat::UI.notify(summary,
                                 title: @options[:title],
                                 image: image,
                                 priority: priority)
      end

      def notify_failure
        return unless options[:notification]
        Guard::Compat::UI.notify("Failed",
                                 title: @options[:title],
                                 image: :failed,
                                 priority: 2)
      end

      private

      def _parse_summary(summary)
        summary.match(/(\d+) failures( \((\d+) pending\))?/) do |m|
          return m[1].to_i, m[3].to_i
        end
        [0, 0]
      end

      def _image(failure_count, pending_count)
        if failure_count > 0
          :failed
        elsif pending_count > 0
          :pending
        else
          :success
        end
      end

      def _priority(image)
        { failed:   2,
          pending: -1,
          success: -2 }[image]
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 6 rubygems

Version Path
honeybadger-5.4.0 vendor/bundle/ruby/3.2.0/gems/guard-rspec-4.7.3/lib/guard/rspec/notifier.rb
honeybadger-5.3.0 vendor/bundle/ruby/3.2.0/gems/guard-rspec-4.7.3/lib/guard/rspec/notifier.rb
honeybadger-4.5.3 vendor/bundle/ruby/2.6.0/gems/guard-rspec-4.7.3/lib/guard/rspec/notifier.rb
alimentos-alu0100945645-0.1.0 vendor/bundle/ruby/2.3.0/gems/guard-rspec-4.7.3/lib/guard/rspec/notifier.rb
alimentos-alu0100945645-1.0.0 vendor/bundle/ruby/2.3.0/gems/guard-rspec-4.7.3/lib/guard/rspec/notifier.rb
comiditaULL-0.1.1 vendor/bundle/ruby/2.3.0/gems/guard-rspec-4.7.3/lib/guard/rspec/notifier.rb
comidita_ull-0.1.1 vendor/bundle/ruby/2.3.0/gems/guard-rspec-4.7.3/lib/guard/rspec/notifier.rb
comidita_ull-0.1.0 vendor/bundle/ruby/2.3.0/gems/guard-rspec-4.7.3/lib/guard/rspec/notifier.rb
gameboard-3.1.0 vendor/bundle/ruby/2.3.0/gems/guard-rspec-4.7.3/lib/guard/rspec/notifier.rb
gameboard-3.0.0 vendor/bundle/ruby/2.3.0/gems/guard-rspec-4.7.3/lib/guard/rspec/notifier.rb
guard-rspec-4.7.3 lib/guard/rspec/notifier.rb
guard-rspec-4.7.2 lib/guard/rspec/notifier.rb
guard-rspec-4.7.1 lib/guard/rspec/notifier.rb
guard-rspec-4.7.0 lib/guard/rspec/notifier.rb