From: James Mead Date: 2009-11-26T21:36:17+09:00 Subject: Re: Mocha multiple_yields with arrays 2009/11/26 Raymond O'Connor : > I believe there's a bug in mocha that causes an unnecessary and annoying > warning message.  If you call multiple_yields with arrays as the arg you > want yielded it will complain. > > object.multiple_yields([1,2], [3,4], [5,6]) > > => prints a warning to the effect: "multiple values for a block > parameter 2 for 1" That code snippet looks wrong. The multiple_yields method is a method on an expectation, so you must call it on the result of e.g. object.stubs or object.expects. I suspect this was a typo and assume you meant something more like this :- object.stubs(:wibble).multiple_yields([1,2], [3,4], [5,6]) In this case, Mocha will invoke the block supplied to the wibble method 3 times and passing in 2 parameters on each invocation. If you supply a block which defines only one parameter you will see the warning you described :- parameters = [] object.wibble { |parameter| parameters << parameter } # => warning: multiple values for a block parameter (2 for 1) p parameters # => [[1,2], [3,4], [5,6]] If you supply a block which defines two parameters you will not see the warning :- parameters = [] object.wibble { |parameter_1, parameter_2| parameters << [parameter_1, parameter_2] } p parameters # => [[1,2], [3,4], [5,6]] So the warning you are seeing is not a problem with Mocha, but due to normal Ruby behaviour which you can see in irb :- irb> def wibble irb> yield(1,2) irb> end => nil irb> wibble { |x| p x } (irb):4: warning: multiple values for a block parameter (2 for 1) from (irb):2 [1, 2] => nil irb> wibble { |x,y| p [x,y] } [1, 2] => nil irb> wibble { |(x,y)| p [x,y] } [1, 2] => nil I hope this helps. If you have any further questions about this, please post to the Mocha mailing list [1] which would be a more appropriate forum. Cheers, James. [1] http://groups.google.com/group/mocha-developer