I have a problem with testing error codes. If the record is not found, it throws an ActiveRecord :: RecordNotFound exception. The thing is, I want to check if 404 is returned. If I continue and just check:
response.status.should == 404
Then this will cause the test case to fail, as the RecordNotFound exception will be thrown and not caught. If I continue and say
expect {<call controller action>}.to raise_error(ActiveRecord::RecordNotFound)
and then check the status code, after which it will fail again, as this will lead to an exception, and the response code is 200.
How to check if 404 returns in this case?
foFox source share