Class: Bunny::Testing

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/bunny/testing.rb,
lib/bunny/testing/version.rb

Constant Summary collapse

VERSION =
"0.2.0"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeTesting

Returns a new instance of Testing.



26
27
28
# File 'lib/bunny/testing.rb', line 26

def initialize
  reset_queue!
end

Instance Attribute Details

#exchangesObject (readonly)

Returns the value of attribute exchanges.



10
11
12
# File 'lib/bunny/testing.rb', line 10

def exchanges
  @exchanges
end

Class Method Details

.exchangesObject



13
14
15
# File 'lib/bunny/testing.rb', line 13

def exchanges
  instance.exchanges
end

.queue(exchange:, routing_key: nil) ⇒ Object



17
18
19
# File 'lib/bunny/testing.rb', line 17

def queue(exchange:, routing_key: nil)
  instance.queue(exchange: exchange, routing_key: routing_key)
end

.reset_queue!Object



21
22
23
# File 'lib/bunny/testing.rb', line 21

def reset_queue!
  instance.reset_queue!
end

Instance Method Details

#queue(exchange:, routing_key: nil) ⇒ Object



30
31
32
33
34
35
36
# File 'lib/bunny/testing.rb', line 30

def queue(exchange:, routing_key: nil)
  messages = exchanges[exchange]

  return messages.find_all { |message| message[:routing_key] == routing_key } unless routing_key.nil?

  messages
end

#reset_queue!Object



38
39
40
# File 'lib/bunny/testing.rb', line 38

def reset_queue!
  @exchanges = Hash.new { |hash, key| hash[key] = [] }
end