Sha256: 188b9f0656f4a4b7a902ccf1cd89fac5bb01730d2abe347b49de2dc25ff6b07b

Contents?: true

Size: 1.77 KB

Versions: 3

Compression:

Stored size: 1.77 KB

Contents

module RabbitFeed
  describe ProducerConnection do
    let(:bunny_exchange)   { double(:bunny_exchange, on_return: nil, publish: nil) }
    let(:bunny_channel)    { double(:bunny_channel, exchange: bunny_exchange, id: 1) }
    let(:bunny_connection) { double(:bunny_connection, start: nil, closed?: false, close: nil, create_channel: bunny_channel) }
    before do
      allow(Bunny).to receive(:new).and_return(bunny_connection)
    end
    subject do
      Class.new(described_class).instance
    end

    describe '#new' do
      it 'sets up returned message handling' do
        expect(described_class).to receive(:handle_returned_message).with('return_info', 'content')
        expect(bunny_exchange).to receive(:on_return).and_yield('return_info', 'properties', 'content')
        subject
      end
    end

    describe '#handle_returned_message' do
      context 'when Airbrake is defined' do
        around do |example|
          module ::Airbrake; end
          example.run
          Object.send(:remove_const, 'Airbrake'.to_sym)
        end

        it 'notifies Airbrake of the return' do
          expect(Airbrake).to receive(:notify).with(an_instance_of(ReturnedMessageError))
          described_class.handle_returned_message 1, 2
        end
      end
    end

    describe '#publish' do
      let(:message) { 'the message' }
      let(:options) { { routing_key: 'routing_key' } }

      it 'publishes the message as mandatory and persistent' do
        expect(bunny_exchange).to receive(:publish).with(message, persistent: true, mandatory: true, routing_key: 'routing_key')
        subject.publish message, options
      end

      it 'is synchronized' do
        expect(subject).to receive(:synchronized).and_call_original
        subject.publish message, options
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
rabbit_feed-3.0.3 spec/lib/rabbit_feed/producer_connection_spec.rb
rabbit_feed-3.0.2 spec/lib/rabbit_feed/producer_connection_spec.rb
rabbit_feed-3.0.1 spec/lib/rabbit_feed/producer_connection_spec.rb