Class: RosettaQueue::Matchers::PublishAMessageTo

Inherits:
Object
  • Object
show all
Defined in:
lib/rosetta_queue/spec_helpers/publishing_matchers.rb

Instance Method Summary collapse

Constructor Details

#initialize(expected_queue_name, options = nil) ⇒ PublishAMessageTo

Returns a new instance of PublishAMessageTo.



6
7
8
9
10
11
# File 'lib/rosetta_queue/spec_helpers/publishing_matchers.rb', line 6

def initialize(expected_queue_name, options=nil)
  @options = options || {}
  @how_many_messages_expected = (@options[:exactly] || 1).to_i
  @expected_queue_name = expected_queue_name
  @expected_queue = expected_queue_name.is_a?(Symbol) ? RosettaQueue::Destinations.lookup(expected_queue_name) : expected_queue_name
end

Instance Method Details

#descriptionObject



32
33
34
# File 'lib/rosetta_queue/spec_helpers/publishing_matchers.rb', line 32

def description
  "publish #{message_plural} to the '#{@expected_queue_name}' queue"
end

#failure_messageObject



24
25
26
# File 'lib/rosetta_queue/spec_helpers/publishing_matchers.rb', line 24

def failure_message
  "expected #{message_plural} published to the #{@expected_queue.inspect} queue but #{@number_of_messages_published} messages were"
end

#matches?(lambda_to_run) ⇒ Boolean

Returns:

  • (Boolean)


13
14
15
16
17
18
19
20
21
22
# File 'lib/rosetta_queue/spec_helpers/publishing_matchers.rb', line 13

def matches?(lambda_to_run)
  #given
  RosettaQueue::Adapter.stub!(:instance).and_return(fake_adapter = RosettaQueue::Gateway::FakeAdapter.new)
  #when
  lambda_to_run.call
  #then
  @actual_queues = fake_adapter.queues
  @number_of_messages_published = @actual_queues.select{ |q| q == @expected_queue}.size
  @number_of_messages_published == @how_many_messages_expected
end

#negative_failure_messageObject



28
29
30
# File 'lib/rosetta_queue/spec_helpers/publishing_matchers.rb', line 28

def negative_failure_message
  "expected ##{message_plural} NOT to be published to the #{@expected_queue.inspect} queue but that queue was published to #{@number_of_messages_published} times"
end