[rspec-users] testing 404 redirects in the controller with rspec beta 19
christoffer.klang at gmail.com
Mon Aug 9 02:29:58 EDT 2010
I'm new to rails and I'm trying to wrap my heads around how to spec
controllers using RSpec (using rails 3rc1 and rspec 2.0.0.beta.19).
The problem I've run into is when I want to test that my controllers respond
with a 404 for unfound records.
Whenever I run the spec, the ActiveRecord::RecordNotFound exception is not
caught by rails, causing the spec example to fail since the exception
propagates out of the controller into the spec.
>From googling around I get that rails only handles the exceptions and does a
404 response when it's run in production mode, and that you need to call
rescue_action_in_public! in your example if you want this behavior for test
mode. However, this does not seem to trigger rails into handling this with a
redirect to 404 even though the @request.remote_addr gets set to
Do I need to set something up for rails to trigger 404 redirecting of
RecordNotFound? Or is this not at all the correct way to test missing
My full example: (using factory_girl, rspec mocks and devise)
it "respons with 404 when trying to edit non-existing reads" do
get :edit, :id => 2
response.status.should eql 404
and the exception:
1) ReadsController resources respons with 404 for non existing reads for GET
Failure/Error: get :edit, :id => 2
View this message in context: http://old.nabble.com/testing-404-redirects-in-the-controller-with-rspec-beta-19-tp29385087p29385087.html
Sent from the rspec-users mailing list archive at Nabble.com.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the rspec-users