Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 534
Javier Perez Avatar asked Jan 31 '26 06:01

Javier Perez


1 Answers

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

like image 175
Alexandr T Avatar answered Feb 03 '26 11:02

Alexandr T



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!