Add mock queue implementation
This commit is contained in:
parent
b9ea7cca30
commit
19afa23021
32
spec/support/mock_queue.rb
Normal file
32
spec/support/mock_queue.rb
Normal file
@ -0,0 +1,32 @@
|
||||
class MockQueue
|
||||
attr_reader :messages
|
||||
|
||||
def initialize
|
||||
@messages = []
|
||||
@subscription_id = 0
|
||||
@subscriptions = {}
|
||||
end
|
||||
|
||||
def subscribe(&block)
|
||||
@subscription_id += 1
|
||||
@subscriptions[@subscription_id] = block
|
||||
@subscription_id
|
||||
end
|
||||
|
||||
def push(message)
|
||||
@messages.push(message)
|
||||
@subscriptions.values.each do |callback|
|
||||
callback.call(message)
|
||||
end
|
||||
message
|
||||
end
|
||||
|
||||
def clear_messages!
|
||||
@messages = []
|
||||
end
|
||||
|
||||
def unsubscribe(subscription_id)
|
||||
@subscriptions.delete(subscription_id)
|
||||
nil
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue
Block a user