# RSpec2 error codes testing

**URL:** <https://www.ruby-forum.com/t/rspec2-error-codes-testing/235863>\
**Category:** RSpec\
**Created:** [July 20, 2013, 2:20pm UTC](https://www.ruby-forum.com/t/rspec2-error-codes-testing/235863 "2013-07-20T14:20:02Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![alcina](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/a587f6/32.png) [@alcina](https://www.ruby-forum.com/u/alcina)\
**Post date:** [July 20, 2013, 2:20pm UTC](https://www.ruby-forum.com/t/rspec2-error-codes-testing/235863/1 "2013-07-20T14:20:02Z")

</div>

I have an issue with testing error codes. If a record is not found, it  
raises exception ActiveRecord::RecordNotFound. The thing is, I wanna  
check if 404 is returned. If I go ahead and just check :

response.status.should == 404

Then this will make the test case fail as RecordNotFound exception is  
thrown and not caught. If I go ahead and say

expect {}.to  
raise\_error(ActiveRecord::RecordNotFound)

and then check for the status code, then it will fail again, as this  
catches the exception and the response code is 200.

How should I test if 404 is returned in this kind of case ?
