[rspec-users] Specifying a specific error is re-raised

Ashley Moran ashley.moran at patchspace.co.uk
Tue Oct 7 09:57:57 EDT 2008


Hi

I've got code I want to intercept all errors (to report them) but re- 
raise them immediately.  Currently the raise_error matcher doesn't  
support matching against instances of exception classes, so I've done  
this to prove that the actual exception was re-raised:

         describe "when the update is unsuccessful" do
           class WeirdError < StandardError; end

           before(:each) do
             @error = WeirdError.new("Error")
             @server.stub!(:check_feeds).and_raise(@error)
           end

           it "should re-raise the exception" do
             lambda { @connection.receive_data("UPDATE\n") }.
               should raise_error(WeirdError)
           end
         end

Few questions:

Is this an appropriate behaviour to spec?

If so, is this currently  the best way to do it?

If so, would exception instance matching be useful?

Thanks
Ashley

-- 
http://www.patchspace.co.uk/
http://aviewfromafar.net/





More information about the rspec-users mailing list