Search code examples
testingruby-on-rails-4rabbitmqbunny

Rails - Test RabbitMQ notifications with Rspec. I am using the bunny gem


I am working on a very small app, it is a RabbitMQ notification system. It triggers an API call when a state changes. That part is fine and I believe is working correctly. What I am having problems is testing the notification part, I am using rspec and I do not have a way to test the notification, or do not know of a way. I have heard of mocking the RabbitMQ call in the test, but I do not know what that means specifically. Can anybody explain? thank you.


Solution

  • For testing app working with rabbitmq you can try evented-spec or moqueue. For example, stubbing connect to AMQP (in moqueue):

    before(:each) do
      reset_broker
      producer.stub(:connect).and_return(mock_exchange(:topic => "common"))
    end
    

    Other examples you can see here