2009/11/27 Phil <
phuib...@gmail.com>:
In Expectation#multiple_yields, the block supplied to the stubbed
method is invoked multiple times per invocation of the stubbed method.
This means that within a single multiple_yields statement, we need to
be able to specify a different set of parameters for each invocation
of the block. There may be any number of parameters for each of these
invocations. So the parameters for each invocation are supplied as an
array. When one of the parameters for one of the block invocations is
itself an array, it's easy to get confused.
The following line :-
object.stubs(:foo).multiple_yields([1,2], [3,4], [5,6])
Mimics the behaviour of a method like this :-
def foo
yield(1, 2)
yield(3, 4)
yield(5, 6)
end
If you want to mimic the behaviour of a method which yields a single
array parameter 3 times like this :-
def foo
yield([1, 2])
yield([3, 4])
yield([5, 6])
end
Then you need a line like this :-
object.stubs(:foo).multiple_yields([[1,2]], [[3,4]], [[5,6]])
In this case, if you supply a block with only one parameter, you
should not get the warning you describe, because each invocation
passes a single array parameter.
object.foo { |only_parameter| p only_parameter }
# => [1, 2]
# => [3, 4]
# => [5, 6]
So unless I'm missing something, I don't think there is bug in Mocha.
I hope this helps.
Cheers, James.