On Tue, Mar 18, 2008 at 11:13 PM, linojon <[EMAIL PROTECTED]> wrote:
> Hi, whats the correct way to spec a rescue? This will raise it but doesnt
> test my code's response
>
>
>
> # controller
>
> def edit
> @foo = Foo.find(params[:id])
> rescue
> flash[:notice] = "Unknown foo #{params[:id]}"
> redirect_to foos_path
> end
>
>
> # spec
>
> it "should flash error if not found" do
> Foo.should_receive(:find).and_raise
> get :edit, :id => '1'
> flash[:notice].should == "Unknown foo 1"
> end
>
> # run
>
> Exception in...
>
>
I have done a very similar thing:
Foo.should_receive(:find).and_raise ActiveRecord::ActiveRecordError
and then change your rescue to handle ActiveRecord::ActiveRecordError.
If you get to the point where you have a generic way you'd like to
handle the exceptions in a controller, or across controllers look into
using the controller class method rescue_from.
I'm not 100% this is what you were asking, hopefully you were just
looking for confirmation,
--
Zach Dennis
http://www.continuousthinking.com
_______________________________________________
rspec-users mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/rspec-users