Sha256: 255c4ee791a1399c83ba33a63410e146facae00931fd6fcdbe0113c609fbc118

Contents?: true

Size: 1.27 KB

Versions: 4

Compression:

Stored size: 1.27 KB

Contents

module Janky
  module Notifier
    # Mock notifier implementation used in testing environments.
    class Mock
      def initialize
        @notifications = []
      end

      attr_reader :notifications

      def queued(build)
      end

      def reset!
        @notifications.clear
      end

      def started(build)
      end

      def completed(build)
        notify(:completed, build)
      end

      def notify(state, build)
        @notifications << [state, build]
      end

      def success?(repo, branch, room_name)
        room_name ||= Janky::ChatService.default_room_name

        builds = @notifications.select do |state, build|
          state == :completed &&
            build.green? &&
            build.repo_name   == repo &&
            build.branch_name == branch &&
            build.room_name   == room_name
        end

        builds.size == 1
      end

      def failure?(repo, branch, room_name)
        room_name ||= Janky::ChatService.default_room_name

        builds = @notifications.select do |state, build|
          state == :completed &&
            build.red? &&
            build.repo_name   == repo &&
            build.branch_name == branch &&
            build.room_name   == room_name
        end

        builds.size == 1
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
janky-0.13.0.pre1 lib/janky/notifier/mock.rb
janky-0.12.0 lib/janky/notifier/mock.rb
janky-0.11.1 lib/janky/notifier/mock.rb
janky-0.11.0 lib/janky/notifier/mock.rb