[rspec-users] specing rescue, ensure and else blocks of an Exception

Ashley Moran work at ashleymoran.me.uk
Fri Oct 26 07:56:04 EDT 2007

On 26 Oct 2007, at 11:55, Tarsoly András wrote:

> So any pointers, help or links to some quick rundown regarding this  
> problem would be greatly appreciated.

 From a brief look over (apologies if I missed something), you are  
not invoking the errors you need to cause your rescue etc blocks to run.

I think you want to do:
   get :action, :id => 1

What you appear to be doing here:

> it "should retrieve a Foo instance, identified by ID and throw an  
> exception, because of bad parameters" do
>   Foo.should_receive(:find).with("1").and_return(@foo)
>   lambda { @foo.should_receive(:update_attributes!).with 
> (valid_params).and_return(@foo) }.should raise_error
>   get :action, :id => 1
> end

is testing that the code throws an exception, NOT that your code  
handles it; ie you are describing an assumption of someone else's  
code rather than the behaviour of yours, which is not what you want  
in a spec.



blog @ http://aviewfromafar.net/
linked-in @ http://www.linkedin.com/in/ashleymoran
currently @ work

More information about the rspec-users mailing list