[rspec-users] How to test for exceptions

Blake Pettersson blake.pettersson at hotmail.com
Sun May 20 13:29:45 EDT 2007

> You generally don't want the controller to raise an error, as it will
> utterly confuse your users to see a Ruby backtrace.
> (Scaffold-generated controllers never raise exceptions). Instead you'd
> want to render a special page when the update fails. Here is what I
> would do:
> describe VenuesController, "on update" do
>   before(:each) do
>     @venue = mock_model(Venue)
>     Venue.should_receive(:find).and_return(@venue)
>   end
>   it "should re-render edit after unsuccessful update" do
>     stub_authorized_login
>     @venue.should_receive(:update_attributes!).and_return(false)
>     put :update
>     response.should render_template('edit')
>   end
> end
> Aslak

I do catch the exceptions. Using the exceptional plugin, I catch any ActiveRecord::RecordInvalid exceptions on create/update and render a new/edit template.

Discover the new Windows Vista

More information about the rspec-users mailing list