Sha256: 81ab8a166346200c5a8b9e644511cab1910f14bd9e77d87a051c1ef3b7d376af

Contents?: true

Size: 1.39 KB

Versions: 11

Compression:

Stored size: 1.39 KB

Contents

# frozen_string_literal: true

require 'rspec/expectations'

RSpec::Matchers.define :dispatch do |message|
  supports_block_expectations

  match do |proc|
    @matched_early = @endpoint.received.detect do |m|
      a_hash_including(message).matches?(m[:message]) && (
        @options.nil? ||
          a_hash_including(@options).matches?(m[:options])
      ) && (
        @message_attributes.nil? || a_hash_including(@message_attributes).matches?(m[:message_attributes])
      )
    end
    return false if @matched_early

    proc.call
    wait_for_async_dispatches

    !!@endpoint.received.detect do |m|
      a_hash_including(message).matches?(m[:message]) && (
        @options.nil? ||
          a_hash_including(@options).matches?(m[:options])
      ) && (
        @message_attributes.nil? || a_hash_including(@message_attributes).matches?(m[:options][:message_attributes])
      )
    end
  end

  chain :to_endpoint do |ep|
    @endpoint = ep
  end

  chain :with_options do |options|
    @options = options
  end

  chain :with_message_attributes do |attributes|
    @message_attributes = attributes
  end


  failure_message do |_actual|
    if @matched_early
      "endpoint already received message that matched: #{message} - message that matched: #{@matched_early}"
    else
      "endpoint did not receive a message with content: #{message} - endpoint messages: #{@endpoint.received}"
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
hermes_messenger_of_the_gods-2.4.0.pre2 lib/hermes_messenger_of_the_gods/testing/dispatch_matcher.rb
hermes_messenger_of_the_gods-2.4.0.pre1 lib/hermes_messenger_of_the_gods/testing/dispatch_matcher.rb
hermes_messenger_of_the_gods-2.3.4 lib/hermes_messenger_of_the_gods/testing/dispatch_matcher.rb
hermes_messenger_of_the_gods-2.3.3 lib/hermes_messenger_of_the_gods/testing/dispatch_matcher.rb
hermes_messenger_of_the_gods-2.3.2 lib/hermes_messenger_of_the_gods/testing/dispatch_matcher.rb
hermes_messenger_of_the_gods-2.3.1 lib/hermes_messenger_of_the_gods/testing/dispatch_matcher.rb
hermes_messenger_of_the_gods-2.3.0 lib/hermes_messenger_of_the_gods/testing/dispatch_matcher.rb
hermes_messenger_of_the_gods-2.2.0 lib/hermes_messenger_of_the_gods/testing/dispatch_matcher.rb
hermes_messenger_of_the_gods-2.1.1 lib/hermes_messenger_of_the_gods/testing/dispatch_matcher.rb
hermes_messenger_of_the_gods-2.1.0 lib/hermes_messenger_of_the_gods/testing/dispatch_matcher.rb
hermes_messenger_of_the_gods-2.0.0 lib/hermes_messenger_of_the_gods/testing/dispatch_matcher.rb