Class: Proletariat::Testing::ExpectationGuarantor::MessageCounter

Inherits:
Actor
  • Object
show all
Defined in:
lib/proletariat/testing/expectation_guarantor.rb

Overview

Internal: Counts incoming messages to test expection satisfaction.

Instance Method Summary collapse

Methods inherited from Actor

#on_message

Methods included from ActorCommon

included, #on_event

Constructor Details

#initialize(expected, count = 0) ⇒ MessageCounter

Public: Creates a new MessageCounter instance.

expected - The number of messages expected.



114
115
116
117
# File 'lib/proletariat/testing/expectation_guarantor.rb', line 114

def initialize(expected, count = 0)
  @count    = count
  @expected = expected
end

Instance Method Details

#expected_messages_received?Boolean

Public: Checks whether message count satifies expected count.

Returns true if count is greater or equal to expected. Returns false if count less than expected.

Returns:

  • (Boolean)


123
124
125
# File 'lib/proletariat/testing/expectation_guarantor.rb', line 123

def expected_messages_received?
  count >= expected
end

#work(message) ⇒ Object

Public: Handles message calls from a subscriber and increments the

count. Return value matches interface expected by Subscriber.

message - The contents of the message. routing_key - Routing key for messages. headers - Hash of message headers.

Returns a future-like object holding an :ok Symbol.



135
136
137
138
139
140
141
142
143
# File 'lib/proletariat/testing/expectation_guarantor.rb', line 135

def work(message)
  if message.is_a?(Message)
    self.count = count + 1

    Concurrent::IVar.new(:ok)
  else
    expected_messages_received?
  end
end