Rails controls the behaviour of its raising / displaying error pages via 
config, and by default for test mode it raises. As Phil points out you should 
be able to configure this should you wish to test the behaviour directly.

You might find these need to be request specs for the displaying errors to work 
however, as I’m not sure where in the Rails rack stack the middleware that 
catches errors is.

Cheers
Jon Rowe
---------------------------
[email protected]
jonrowe.co.uk

On 11 July 2020 at 01:30, Jack Royal-Gordon wrote:
> I have read (and experienced by testing) that if, in a controller, you do a 
> AR#find on a record id that does not exist, it throws an AR::RecordNotFound 
> error which is trapped by the default error handling in controllers and 
> results in a 404 status being returned by the controller. This happens with 
> no special code added by the user.
>
> I have a test to verify this behavior, and it’s not working.
>
> it “fails on an invalid record ID” do
> get :show, id: -1
> response.should_not be_success
> end
>
>
> This test produces:
> > Failure/Error: get 'show', id: -1
> > ActiveRecord::RecordNotFound:
> > Couldn't find Group with id=-1
>
>
>
> What am I missing?

-- 
You received this message because you are subscribed to the Google Groups 
"rspec" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rspec/dejalu-217-e4a6438c-4d3c-49af-b56f-867b782b8ea9%40jonrowe.co.uk.

Reply via email to