Sha256: d953094b2fd33553ede0a0da68f93f7aca7aff7ccbf9b9510eb07d6ebf431c29

Contents?: true

Size: 1.83 KB

Versions: 4

Compression:

Stored size: 1.83 KB

Contents

require 'rabbit_feed/console_consumer'

module RabbitFeed
  describe ConsoleConsumer do
    let(:purge) { 'n' }
    let(:queue_depth) { 0 }
    let(:connection) { double(:connection, queue_depth: queue_depth) }
    before do
      allow(ConsumerConnection).to receive(:instance).and_return(connection)
      allow(STDIN).to receive(:gets).and_return(purge)
    end

    describe '#init' do
      it 'prints a welcome message' do
        expect { subject.init }.to output(
          /RabbitFeed console starting at .* UTC\.\.\.\nEnvironment: test\nQueue: test\.rabbit_feed_console\nReady\. Press CTRL\+C to exit\./
        ).to_stdout
      end

      context 'when there are events on the rabbit_feed_console queue' do
        let(:queue_depth) { 1 }

        it 'asks to purge the queue' do
          expect { subject.init }.to output(
            %r{There are currently 1 message\(s\) in the console's queue\.\nWould you like to purge the queue before proceeding\? \(y\/N\)>}
          ).to_stdout
        end

        context 'when the user wishes to purge the queue' do
          let(:purge) { 'y' }

          it 'purges the queue' do
            expect(connection).to receive(:purge_queue)
            expect { subject.init }.to output(/Queue purged\./).to_stdout
          end
        end
      end
    end

    describe 'receiving an event' do
      let(:event) { Event.new({ name: 'name' }, key: :value) }
      before { subject.init }

      it 'prints the event' do
        expect { rabbit_feed_consumer.consume_event event }.to output(
/-----------------------------------------------name: -----------------------------------------------
#Event metadata
name: name
(\*)+
#Event payload
key: value
----------------------------------------------------------------------------------------------------
1 events received\./
        ).to_stdout
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

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