It's a common setup to survise a credit card applicatoin having a heartbeat message by some monitoring tool, for instance Monit. When the application is running and things are working properly, it returns an "I'm alive" message, when the database fails or even the web server dangles it returns nothing or perhaps an internal server error (HTTP status code 500) page. How will you simulate a database failure to check this behavior in Ruby on Rails? It might be nice if a person could enable/disable this feature for test reasons inside the test (Test::Unit or RSpec) itself.

It appears like it's possible to use ActiveRecord::Base.remove_connection to simulate a database failure. Using RSpec this could seem like:

  describe "GET running" do
    it "renders a 500 if crashed" do
      ActiveRecord::Base.remove_connection
      get :running
      response.response_code.should == 500
      ActiveRecord::Base.establish_connection
    end
  end