class BunnyMock::Queue
Attributes
attrs[RW]
delivery_count[RW]
messages[RW]
name[RW]
Public Class Methods
new(name, attrs = {})
click to toggle source
# File lib/bunny_mock.rb, line 52 def initialize(name, attrs = {}) self.name = name self.attrs = attrs.dup self.messages = [] self.delivery_count = 0 end
Public Instance Methods
bind(exchange)
click to toggle source
# File lib/bunny_mock.rb, line 59 def bind(exchange) exchange.queues << self end
default_consumer()
click to toggle source
# File lib/bunny_mock.rb, line 75 def default_consumer BunnyMock::Consumer.new(self.delivery_count) end
method_missing(method, *args)
click to toggle source
Calls superclass method
# File lib/bunny_mock.rb, line 89 def method_missing(method, *args) method_name = method.to_s is_predicate = false if method_name =~ /^(.*)\?$/ key = $1.to_sym is_predicate = true else key = method.to_sym end if attrs.has_key? key value = attrs[key] is_predicate ? !!value : value else super end end
publish(msg)
click to toggle source
# File lib/bunny_mock.rb, line 71 def publish(msg) self.messages << msg end
snapshot_messages()
click to toggle source
NOTE: This is NOT a method that is supported on real Bunny queues.
This is a custom method to get us a deep copy of all the messages currently in the queue. This is provided to aid in testing a system where it is not practical for the test to subscribe to the queue and read the messages, but we need to verify that certain messages have been published.
# File lib/bunny_mock.rb, line 85 def snapshot_messages Marshal.load(Marshal.dump(messages)) end
subscribe(*args) { |{:payload => message}| ... }
click to toggle source
Note that this doesn't block waiting for messages like the real world.
# File lib/bunny_mock.rb, line 64 def subscribe(*args, &block) while message = messages.shift self.delivery_count += 1 yield({:payload => message}) end end