Class: Proletariat::Testing::ExpectationGuarantor::MessageCounter
- Inherits:
-
Actor
- Object
- Concurrent::Actor::RestartingContext
- Actor
- Proletariat::Testing::ExpectationGuarantor::MessageCounter
- Defined in:
- lib/proletariat/testing/expectation_guarantor.rb
Overview
Internal: Counts incoming messages to test expection satisfaction.
Instance Method Summary collapse
-
#expected_messages_received? ⇒ Boolean
Public: Checks whether message count satifies expected count.
-
#initialize(expected, count = 0) ⇒ MessageCounter
constructor
Public: Creates a new MessageCounter instance.
-
#work(message) ⇒ Object
Public: Handles message calls from a subscriber and increments the count.
Methods inherited from Actor
Methods included from ActorCommon
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.
123 124 125 |
# File 'lib/proletariat/testing/expectation_guarantor.rb', line 123 def 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() if .is_a?(Message) self.count = count + 1 Concurrent::IVar.new(:ok) else end end |