arempe93 / bunny-mock

A mock client for RabbitMQ modeled after the Bunny client in ruby
http://www.rubydoc.info/github/arempe93/bunny-mock
MIT License
44 stars 37 forks source link

Examples for raising errors #10

Open dsandstrom opened 8 years ago

dsandstrom commented 8 years ago

Can you provide an example on how to raise Bunny::ConnectionClosedError and Bunny::TCPConnectionFailed errors. I'm having trouble getting these to fire.

Maybe something like:

it 'should route messages from exchanges' do
  channel = BunnyMock.new.start.channel

  xchg = channel.topic 'xchg.topic'
  queue = channel.queue 'queue.test'

  queue.bind xchg
  allow(xchg).to receive(:publish).and_raise(Bunny::ConnectionClosedError)
  xchg.publish 'Routed message', routing_key: '*.test'

  expect(queue.message_count).to eq(1)
  expect(queue.pop[:message]).to eq('Routed message')
end
arempe93 commented 8 years ago

Hmmm....perhaps I can have a toggle to simulate certain errors. Something like

session.simulate_connection_closed!

expect {  xchg.publish('Routed message', routing_key: '*.test') }.to raise_error(Bunny::ConnectionClosedError)
expect(error_handler).to do_stuff

I'll have to look at this and the relevant Bunny code to see what the actual implementation of that might look like tonight