Is there a way to write tests for 500 error page in Rails?

Here's what I do, assuming you're using rspec, rspec-mocks and capybara: First, you need to find a controller action that calls a method. For example, you might have a UserController with a show action that calls User.find. In that case, you can do something like this:

it "should render the 500 error page when an error happens" do
  # simulate an error in the user page
  User.should_receive(:find).and_raise("some fancy error")
  visit '/user/1'

  # verify status code
  page.status_code.should eql(500)

  # verify layout
  page.title.should eql('Your site title')
  page.should have_css('navigation')
  page.should have_css('.errors')
end

So what I found out was that I could do something like this in rspec

def other_error
   raise "ouch!"
end

it "renders 500 on Runtime error" do
  get :other_error
  response.should render_template("errors/500")
  response.status.should == 500
end