Sha256: 3c2e0297793e56ae00224eb887d4bab825243ba61237d27ab43662e73f1a1e2b

Contents?: true

Size: 941 Bytes

Versions: 2

Compression:

Stored size: 941 Bytes

Contents

require_relative "test_helper"

class ConsumableTest < Test::Unit::TestCase
  class Consumer
    attr_reader :message

    include MessageQueue::Consumable
  end

  def setup
    MessageQueue.connect(:adapter => :bunny, :serializer => :plain)
  end

  def teardown
    MessageQueue.disconnect
  end

  def test_consumable
    producer = MessageQueue.new_producer(
      :exchange => {
        :name => "test_consumable",
        :type => :direct,
        :auto_delete => true
      },
      :message => {
        :routing_key => "test_consumable"
      }
    )

    Consumer.queue :name => "test_consumable", :auto_delete => true
    Consumer.exchange :name => "test_consumable"
    Consumer.send(:define_method, :process) do |message|
      @message = message
    end
    consumer = Consumer.new
    consumer.subscribe

    msg = Time.now.to_s
    producer.publish msg

    sleep 1

    assert_equal msg, consumer.message.payload
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
message_queue-0.1.1 test/consumable_test.rb
message_queue-0.1.0 test/consumable_test.rb