When you need a rabbit, spec it

February 7, 2014

On my current project, we're using RabbitMQ. It's a bit of infrastructure that has to be present, and if it isn't, our integration tests will fail with mysterious error messages. We want our tests to be informative, so let's write a test that asserts that we have the requisite infrastructure in place.

require "bunny"
require "bunny/exceptions"

describe "RabbitMQ" do
  it "is running" do
    rabbitmq_is_available.should be_true
  end

  def rabbitmq_is_available
    begin
      Bunny.new("... amqp configuration uri ...")
      true
    rescue Bunny::TCPConnectionFailed
      false
    end
  end
end

Run this test and you will know whether the underlying RabbitMQ infrastructure is running.

When you need a rabbit, spec it - February 7, 2014 - Ken Mayer