Module: Asynk::TestHelper
- Defined in:
- lib/asynk/test_helper.rb
Defined Under Namespace
Classes: BunnyMockedChannel, BuunyMockedDeliveryInfo, BuunyMockedProperties
Instance Method Summary
collapse
Instance Method Details
#asynk_response ⇒ Object
26
27
28
|
# File 'lib/asynk/test_helper.rb', line 26
def asynk_response
@asynk_response
end
|
#asynk_response=(response) ⇒ Object
22
23
24
|
# File 'lib/asynk/test_helper.rb', line 22
def asynk_response=(response)
@asynk_response = response
end
|
#find_consumers_by_route(route) ⇒ Object
30
31
32
|
# File 'lib/asynk/test_helper.rb', line 30
def find_consumers_by_route(route)
Asynk.consumers.select{ |consumer| consumer.routing_keys.any?{ |key| key == route } }
end
|
#publish_sync(routing_key, options) ⇒ Object
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
# File 'lib/asynk/test_helper.rb', line 3
def publish_sync(routing_key, options)
consumers = find_consumers_by_route(routing_key)
raise "Cant find consumer by route: #{routing_key}" if consumers.empty?
raise "No ability to test multiple consumer per route" if consumers.count > 1
consumer = consumers.first
bunny_mocked_channel = BunnyMockedChannel.new
bunny_mocked_delivery_info = BuunyMockedDeliveryInfo.new(routing_key)
bunny_mock_properties = BuunyMockedProperties.new
message = Asynk::Message.new(bunny_mocked_delivery_info, bunny_mock_properties, options.to_json)
consumer_instance = consumer.new(bunny_mocked_channel, bunny_mocked_delivery_info) do |result|
self.asynk_response = result.kind_of?(String) ? result : result.to_json
end
consumer_instance.invoke_processing(message)
asynk_response
end
|