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

Rick DeNatale rick.denatale at gmail.com
Wed Apr 9 12:33:32 EDT 2008

On Wed, Apr 9, 2008 at 11:54 AM, David Chelimsky <dchelimsky at gmail.com> wrote:

>  What are you looking to specify and how do you envision the syntax?
>  I'm thinking something like:
>  obj.should yield_with(no_args).on(:message)
>  def message
>   yield
>  end
>  list.should yield_with(1).then(2).then(3).on(:each)
>  def each
>   yield 1
>   yield 2
>   yield 3
>  end
>  That all make sense?

Sorta, but what about arguments to the message?

def message(x, y, z)
   yield x+y+z

obj.receiving(:message).with(1,2,3).should yield(6)



(1..3).receiving(:each_with_index).should yield_with([1,0],([2,1],[3,2])

(1..3).receiving(:inject).with(0).should yield_with  ???????

Now it gets tricky since the sequence of yielded values depends on the block .

I don't know that I like where this is going.

Rick DeNatale

My blog on Ruby

More information about the rspec-users mailing list