spec/lib/adapters/rabbitmq_adapter_spec.rb in basquiat-1.2.0 vs spec/lib/adapters/rabbitmq_adapter_spec.rb in basquiat-1.3.0.pre.1
- old
+ new
@@ -3,12 +3,12 @@
describe Basquiat::Adapters::RabbitMq do
subject(:adapter) { Basquiat::Adapters::RabbitMq.new }
let(:base_options) do
- { servers: [{ host: ENV.fetch('BASQUIAT_RABBITMQ_1_PORT_5672_TCP_ADDR') { 'localhost' },
- port: ENV.fetch('BASQUIAT_RABBITMQ_1_PORT_5672_TCP_PORT') { 5672 } }],
+ { connection: { hosts: [ENV.fetch('BASQUIAT_RABBITMQ_1_PORT_5672_TCP_ADDR') { 'localhost' }],
+ port: ENV.fetch('BASQUIAT_RABBITMQ_1_PORT_5672_TCP_PORT') { 5672 } },
publisher: { persistent: true } }
end
context 'RabbitMQ interactions' do
before(:each) do
@@ -27,36 +27,40 @@
end.to_not raise_error
end
end
context 'listener' do
+ it 'runs the rescue block when an exception happens' do
+ coisa = ''
+ adapter.subscribe_to('some.event', ->(_msg) { fail ArgumentError })
+ adapter.listen(block: false, rescue_proc: -> (ex, _msg) { coisa = ex.class.to_s })
+ adapter.publish('some.event', data: 'coisa')
+ sleep 0.7
+
+ expect(coisa).to eq('ArgumentError')
+ end
+
it '#subscribe_to some event' do
message = ''
- adapter.subscribe_to('some.event',
- ->(msg) { message << msg[:data].upcase! })
+ adapter.subscribe_to('some.event', ->(msg) { message = msg[:data].upcase })
adapter.listen(block: false)
- adapter.publish('some.event', data: 'coisa')
- sleep 0.7 # Wait for the listening thread
+ adapter.publish('some.event', data: 'message')
+ sleep 0.7
- expect(message).to eq('COISA')
+ expect(message).to eq('MESSAGE')
end
end
- it '#subscribe_to other event with #' do
+ it '#subscribe_to other.event with #' do
message_received = ''
- subject.subscribe_to('other.event.#',
- lambda do |msg|
- msg[:data].upcase!
- message_received = msg
- end)
+ subject.subscribe_to('other.event.#', ->(msg) { message_received = msg[:data].upcase })
subject.listen(block: false)
- subject.publish('other.event.extra.info', data: 'some stuff')
- sleep 0.3 # Wait for the listening thread.
+ subject.publish('other.event.test', data: 'some stuff')
+ sleep 0.7
- expect(message_received).to eq(data: 'SOME STUFF')
+ expect(message_received).to eq('SOME STUFF')
end
-
end
def remove_queues_and_exchanges
adapter.session.queue.delete
adapter.session.exchange.delete