views:

67

answers:

1

I want to verify that an exception is being thrown in some function tests by calling get :methodname, :params. I had expected just making this call and then verifying the result is a 500 would be sufficient, but rails is failing the test as soon as the exception is reached in the get. While I figure I could go ahead and wrap the get in a rescue and verify the exception is thrown myself, and would hope there's a better method for doing this.

What's the best way to verify an exception is thrown when using a get in your tests?

+3  A: 

You can do:

def test_sommat
  assert_raises SomeException do
    get :methodname, params
  end
end
Shadwell