Sha256: 73b632ba8320b3c0d13a972b606aeea64f816607b74af39f066e056b7286688d

Contents?: true

Size: 1.27 KB

Versions: 1

Compression:

Stored size: 1.27 KB

Contents

require 'rabbit_rpc'

describe RabbitRPC::SynchronousConnection do
  describe '#publish!' do
    let(:connection)      { RabbitRPC::SynchronousConnection.new('foo', 'bar', 'amqp:://localhost:5672') }
    let(:exchange)        { double 'exchange', publish: true }
    let(:message)         { RabbitRPC::Message.new 'User.create', 'bar' }
    let(:one_way_message) { RabbitRPC::Message.new 'User.one_way_create', 'bar' }
    let(:queue)           { double 'queue', subscribe: true }

    before do
      connection.stub(:exchange).and_return exchange
      connection.stub(:callback_queue).and_return queue
    end

    it 'sends a message to the relevant queue' do
      exchange.should_receive(:publish).with(
        message.pack,
        routing_key: 'foo',
        message_id:  anything(),
        reply_to:    'bar',
        auto_delete: false
      )
      connection.publish! message
    end

    context 'when a response is expected' do
      it 'subscribes to the callback queue to listen for a response' do
        queue.should_receive :subscribe
        connection.publish!(message)
      end
    end

    context 'when no response is expected' do
      it 'terminates' do
        queue.should_not_receive :subscribe
        connection.publish!(one_way_message)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rabbit_rpc-0.0.2 spec/synchronous_connection_spec.rb