Sha256: 6c19195b7e95178f2eebbce62d3fae32313c8ab6e8f0a8663a1bcf8cd738aabd

Contents?: true

Size: 1.42 KB

Versions: 9

Compression:

Stored size: 1.42 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"
      Propono.expects(:listen_to_queue).with("#{topic_name}")
      Larva::Listener.listen(topic_name, nil)
    end

    def test_listener_logs_listening_message
      topic_name = "Foo"
      message = "Starting to listen to queue #{topic_name}"
      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

9 entries across 9 versions & 1 rubygems

Version Path
larva-1.3.0 test/listener_test.rb
larva-1.2.0 test/listener_test.rb
larva-1.1.3 test/listener_test.rb
larva-1.1.2 test/listener_test.rb
larva-1.1.1 test/listener_test.rb
larva-1.1.0 test/listener_test.rb
larva-1.0.1 test/listener_test.rb
larva-1.0.0 test/listener_test.rb
larva-0.9.2 test/listener_test.rb