[rspec-users] What is the best way to verify that yield is called?

Ben Mabey ben at benmabey.com
Wed Apr 9 10:59:10 EDT 2008


>>
>>       it "should yield the given block" do
>>         @block_yieled = false
>>         create_message_in_factory do |message_delivery|
>>           @block_yieled = true
>>         end
>>         @block_yieled.should be_true
>>       end
>>
>>
>>  Seems kinda hackish, but it did work.  Is this the best way to spec this
>>  or is there already a matcher for this?
>>     
>
> Another approach might be:
>
>     it "should yield the given block" do
>         block_body = mock("block body")
>         block_body.should_receive(:got_here)
>         create_message_in_factory_do | message_delivery |
>             block_body.got_here
>         end
>    end
>
>
>
>
>
>   
Thanks Rick!
Both of these way work but I think they are both too ugly and should be 
created into a more expressive matcher. 
Given the above two options can anyone see an advantage to one way or 
the other?  Or maybe another option is out there that is better?

Thanks,
Ben


More information about the rspec-users mailing list