Sha256: 308a4da60ad0083a8726eaa04d64f9ce7d150f3eb2f15da8ffc1d08eadee1623

Contents?: true

Size: 1.54 KB

Versions: 1

Compression:

Stored size: 1.54 KB

Contents

require 'spec_helper.rb'

describe Pwwka::Receiver do
  describe "#new" do
    let(:handler_klass) { double('HandlerKlass') }
    let(:channel_connector) { double(Pwwka::ChannelConnector, topic_exchange: topic_exchange, channel: channel)}
    let(:topic_exchange) { double("topic exchange") }
    let(:channel) { double('channel', queue: queue) }
    let(:queue) { double('queue') }
    let(:queue_name) { 'test_queue_name' }

    subject {
      described_class.subscribe(
        handler_klass,
        queue_name
      )
    }

    before do
      allow(Pwwka::ChannelConnector).to receive(:new).and_return(channel_connector)
      allow(handler_klass).to receive(:handle!)
      allow(channel_connector).to receive(:connection_close)
      allow(queue).to receive(:bind)
      allow(queue).to receive(:subscribe).and_yield({}, {}, '{}')
    end

    it 'sets the correct connection_name' do
      subject
      expect(Pwwka::ChannelConnector).to have_received(:new).with(prefetch: nil, connection_name: "c: #{queue_name}")
    end

    it 'closes the conenction on an error' do
      error = 'oh no'
      allow(handler_klass).to receive(:handle!).and_raise(error)
      begin; subject; rescue; end
      expect(channel_connector).to have_received(:connection_close)
    end

    it 'logs on interrupt' do
      allow(handler_klass).to receive(:handle!).and_raise(Interrupt)
      allow(described_class).to receive(:info)
      begin; subject; rescue; end
      expect(described_class).to have_received(:info).with(/Interrupting queue #{queue_name}/)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
pwwka-0.20.0 spec/unit/receiver_spec.rb