From c6014e4c95541aa34af34978e9a614fb49cea606 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20Lu=CC=88dke?= Date: Thu, 26 Oct 2023 15:00:44 +0200 Subject: [PATCH] Add test --- spec/ears/setup_spec.rb | 46 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/spec/ears/setup_spec.rb b/spec/ears/setup_spec.rb index 8642821..fcfb49c 100644 --- a/spec/ears/setup_spec.rb +++ b/spec/ears/setup_spec.rb @@ -7,6 +7,52 @@ before { allow(Ears).to receive(:channel).and_return(ears_channel) } + # rubocop:disable RSpec/SubjectStub + describe '#setup_consumers' do + let(:consumers) do + [ + class_double( + Ears::Consumer, + exchange: 'my-exchange', + queue: 'my-queue', + exchange_type: :topic, + durable_exchange: true, + queue_options: { + my_option: true, + }, + routing_key: 'my_key', + ), + ] + end + let(:an_exchange) { instance_double(Bunny::Exchange) } + let(:a_queue) { instance_double(Bunny::Queue, bind: nil) } + + before do + allow(setup).to receive_messages(exchange: an_exchange, queue: a_queue) + allow(setup).to receive(:consumer) + end + + it 'sets up the consumers accordingly including its queues etc.' do + setup.setup_consumers(*consumers) + + expect(setup).to have_received(:exchange).with( + 'my-exchange', + :topic, + durable: true, + ) + expect(setup).to have_received(:queue).with( + 'my-queue', + { my_option: true }, + ) + expect(a_queue).to have_received(:bind).with( + an_exchange, + routing_key: 'my_key', + ) + expect(setup).to have_received(:consumer).with(a_queue, consumers[0]) + end + end + # rubocop:enable RSpec/SubjectStub + describe '#exchange' do it 'creates a new Bunny exchange with the given options' do expect(Bunny::Exchange).to receive(:new).with(