[rspec-users] Trouble validating an exception

Pat Maddox pergesu at gmail.com
Mon Feb 2 19:24:11 EST 2009


On Mon, Feb 2, 2009 at 4:22 PM, Pat Maddox <pergesu at gmail.com> wrote:
> On Mon, Feb 2, 2009 at 3:30 PM, Ben Greenberg
> <mailing_lists at bengreenberg.net> wrote:
>> Hi all,
>>
>> This spec always passes:
>>
>>    lambda do
>>      process_card @credit_card, billing_info, 10604, '1.1.1.1', @gateway
>>    end.should raise_error(MinimalCart::CaptureFailureError) do |ex|
>>      ex.should be_nil
>>      ex.should_not be_nil
>>      ex.responses.should be_nil
>>      ex.responses.should_include @auth_response
>>      ex.responses.include?.with('a').should be_true
>>    end
>>
>> Clearly, it makes no sense.  Somehow the exception validation block is not
>> running.  What am I doing wrong?
>
> try using { } instead of do..end.  Pretty sure that the problem you're
> experiencing has to do with Ruby's block precedence.

oops I should have been more specific.  I meant use { } for the block
after raise_error:

 lambda do
     process_card @credit_card, billing_info, 10604, '1.1.1.1', @gateway
   end.should raise_error(MinimalCart::CaptureFailureError) { |ex|
     ex.should be_nil
     ex.should_not be_nil
     ex.responses.should be_nil
     ex.responses.should_include @auth_response
     ex.responses.include?.with('a').should be_true
   }

Although I think that do..end.method is hideous and so I would change
the lambda to use curly braces as well :)

Pat


More information about the rspec-users mailing list