Class: Pwwka::TestHandler
- Inherits:
-
Object
- Object
- Pwwka::TestHandler
- Includes:
- Logging
- Defined in:
- lib/pwwka/test_handler.rb
Overview
A handler you can use to examine messages your app sends during tests.
To use this:
-
Create an instance and arrange for ‘test_setup` to be called when your tests are being setup (e.g.`def setup` or `before`)
-
Arrange for ‘test_teardown` to be called during teardown of your tests
-
Use the method ‘pop_message` to examine the message on the queue
Defined Under Namespace
Classes: Message
Constant Summary
Constants included from Logging
Instance Attribute Summary collapse
-
#channel_connector ⇒ Object
readonly
Returns the value of attribute channel_connector.
Instance Method Summary collapse
- #get_topic_message_delivery_info_for_tests ⇒ Object
- #get_topic_message_payload_for_tests ⇒ Object
- #get_topic_message_properties_for_tests ⇒ Object
-
#initialize ⇒ TestHandler
constructor
A new instance of TestHandler.
-
#pop_message ⇒ Object
Get the message on the queue as TestHandler::Message.
- #purge_test_queue ⇒ Object
- #test_queue ⇒ Object
-
#test_setup ⇒ Object
call this method to create the queue used for testing queue needs to be declared before the exchange is published to.
- #test_teardown ⇒ Object
Methods included from Logging
Constructor Details
#initialize ⇒ TestHandler
Returns a new instance of TestHandler.
15 16 17 |
# File 'lib/pwwka/test_handler.rb', line 15 def initialize @channel_connector = ChannelConnector.new end |
Instance Attribute Details
#channel_connector ⇒ Object (readonly)
Returns the value of attribute channel_connector.
13 14 15 |
# File 'lib/pwwka/test_handler.rb', line 13 def channel_connector @channel_connector end |
Instance Method Details
#get_topic_message_delivery_info_for_tests ⇒ Object
54 55 56 57 58 |
# File 'lib/pwwka/test_handler.rb', line 54 def deprecated!(:get_topic_message_delivery_info_for_tests, "Use `pop_message.delivery_info` instead") .delivery_info end |
#get_topic_message_payload_for_tests ⇒ Object
42 43 44 45 46 |
# File 'lib/pwwka/test_handler.rb', line 42 def deprecated!(:get_topic_message_payload_for_tests, "Use `pop_message.payload` instead") .payload end |
#get_topic_message_properties_for_tests ⇒ Object
48 49 50 51 52 |
# File 'lib/pwwka/test_handler.rb', line 48 def deprecated!(:get_topic_message_properties_for_tests, "Use `pop_message.properties` instead") .properties end |
#pop_message ⇒ Object
Get the message on the queue as TestHandler::Message
35 36 37 38 39 40 |
# File 'lib/pwwka/test_handler.rb', line 35 def delivery_info, properties, payload = test_queue.pop Message.new(delivery_info, properties, payload) end |
#purge_test_queue ⇒ Object
60 61 62 63 |
# File 'lib/pwwka/test_handler.rb', line 60 def purge_test_queue test_queue.purge channel_connector.delayed_queue.purge if channel_connector.configuration.allow_delayed? end |
#test_queue ⇒ Object
26 27 28 29 30 31 32 |
# File 'lib/pwwka/test_handler.rb', line 26 def test_queue @test_queue ||= begin test_queue = channel_connector.channel.queue("test-queue", durable: true) test_queue.bind(channel_connector.topic_exchange, routing_key: "#.#") test_queue end end |
#test_setup ⇒ Object
call this method to create the queue used for testing queue needs to be declared before the exchange is published to
21 22 23 24 |
# File 'lib/pwwka/test_handler.rb', line 21 def test_setup test_queue true end |
#test_teardown ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/pwwka/test_handler.rb', line 65 def test_teardown test_queue.delete channel_connector.topic_exchange.delete # delayed messages if Pwwka.configuration.allow_delayed? channel_connector.delayed_queue.delete channel_connector.delayed_exchange.delete end channel_connector.connection_close end |