class Pwwka::TestHandler
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
Attributes
channel_connector[R]
Public Class Methods
new()
click to toggle source
# File lib/pwwka/test_handler.rb, line 15 def initialize @channel_connector = ChannelConnector.new end
Public Instance Methods
get_topic_message_delivery_info_for_tests()
click to toggle source
# File lib/pwwka/test_handler.rb, line 54 def get_topic_message_delivery_info_for_tests deprecated!(:get_topic_message_delivery_info_for_tests, "Use `pop_message.delivery_info` instead") pop_message.delivery_info end
get_topic_message_payload_for_tests()
click to toggle source
# File lib/pwwka/test_handler.rb, line 42 def get_topic_message_payload_for_tests deprecated!(:get_topic_message_payload_for_tests, "Use `pop_message.payload` instead") pop_message.payload end
get_topic_message_properties_for_tests()
click to toggle source
# File lib/pwwka/test_handler.rb, line 48 def get_topic_message_properties_for_tests deprecated!(:get_topic_message_properties_for_tests, "Use `pop_message.properties` instead") pop_message.properties end
pop_message()
click to toggle source
Get the message on the queue as TestHandler::Message
# File lib/pwwka/test_handler.rb, line 35 def pop_message delivery_info, properties, payload = test_queue.pop Message.new(delivery_info, properties, payload) end
purge_test_queue()
click to toggle source
# 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()
click to toggle source
# 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()
click to toggle source
call this method to create the queue used for testing queue needs to be declared before the exchange is published to
# File lib/pwwka/test_handler.rb, line 21 def test_setup test_queue true end
test_teardown()
click to toggle source
# 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
Private Instance Methods
deprecated!(method,message)
click to toggle source
# File lib/pwwka/test_handler.rb, line 101 def deprecated!(method,message) warn "#{method} is deprecated: #{message}" end