Sha256: f37eda49072815e2eed11dd5bbe5f3b2202d42627da6d914d3ce18d162edfc7c

Contents?: true

Size: 1.59 KB

Versions: 13

Compression:

Stored size: 1.59 KB

Contents

require File.expand_path('../test_helper', __FILE__)

module Larva
  class ListenerTest < Minitest::Test
    def test_listen_to_queue_is_called
      topic_name = "Foo"
      queue_suffix = "bar"
      Propono.config.queue_suffix = queue_suffix
      Propono.expects(:listen_to_queue).with("#{topic_name}#{queue_suffix}")
      Larva::Listener.listen(topic_name, nil)
    end

    def test_listener_logs_listening_message
      topic_name = "Foo"
      queue_suffix = "bar"
      Propono.config.queue_suffix = queue_suffix

      message = "Starting to listen to queue #{topic_name}#{queue_suffix}"
      Propono.config.logger.expects(:info).with(message)
      Propono.stubs(:listen_to_queue)
      Larva::Listener.listen(topic_name, nil)
    end

    def test_listener_changes_context
      context = {id: "34sdf"}
      Propono.config.logger.expects(:context_id=).with(context[:id])
      Propono.stubs(:listen_to_queue).yields(nil, context)
      Larva::Listener.listen("foobar", mock(process: nil))
    end

    def test_listener_logs_message
      message = {foo: 'bar'}
      context = {id: "34sdf"}
      Propono.config.logger.stubs(:info)
      Propono.config.logger.expects(:info).with("Received message: #{message}")
      Propono.stubs(:listen_to_queue).yields(message, context)
      Larva::Listener.listen("foobar", mock(process: nil))
    end

    def test_processor_is_called_with_message
      processor = mock
      message = {foo: 'bar'}
      processor.expects(:process).with(message)
      Propono.expects(:listen_to_queue).yields(message, {})
      Larva::Listener.listen("foobar", processor)
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
larva-0.9.1 test/listener_test.rb
larva-0.9.0 test/listener_test.rb
larva-0.8.0 test/listener_test.rb
larva-0.7.3 test/listener_test.rb
larva-0.7.2 test/listener_test.rb
larva-0.7.1 test/listener_test.rb
larva-0.7.0 test/listener_test.rb
larva-0.6.4 test/listener_test.rb
larva-0.6.3 test/listener_test.rb
larva-0.6.2 test/listener_test.rb
larva-0.6.1 test/listener_test.rb
larva-0.6.0 test/listener_test.rb
larva-0.5.0 test/listener_test.rb