#84 ✓resolved
Matthew W

Mocking 'each' method with yields/multiple_yields behaves incorrectly under JRuby

Reported by Matthew W | February 17th, 2011 @ 03:30 PM

I get different results under JRuby (1.5.6 but also seen under 1.5.2) and MRI for this. Using the latest mocha (0.9.12).

jruby :001 > require 'mocha'; o = Object.new; o.extend Enumerable; o.stubs(:each).multiple_yields(1,2); p o.to_a
[[1], [2]]

whereas this is what I see as being the correct behaviour under MRI:

ruby-1.8.7-p302 :001 > require 'mocha'; o = Object.new; o.extend Enumerable; o.stubs(:each).multiple_yields(1,2); p o.to_a
[1, 2]

The difference is visible via other enumerable methods too (map, select, etc), but, interestingly, not when calling 'each' directly. So eg o.each {|x| p x} has different output to o.map {|x| p x}.

I wasn't able to replicate the problem using other methods of stubbing the each method, only with mocha. Possibly a somewhat strange interaction between Mocha's magic and slight differences in the under-the-hood Enumerable implementations between these ruby platforms.

Would be good if this could either be fixed or worked around in mocha, or if it's actually a JRuby bug, pinned down and replicated without mocha so it can be reported to JRuby or a test case added to rubyspec.

Comments and changes to this ticket

  • James Mead

    James Mead February 27th, 2011 @ 08:04 PM

    • Tag changed from jruby enumerable mocha yields multiple_yields bug each to bug-report, each, enumerable, jruby, multiple_yields, yields

    Hmm. I wonder whether this is related to this other ticket. Have you tried it under MRI Ruby 1.9.2?

    Sorry I haven't got much time to look into this at the moment. Will try to as soon as I can.

  • James Mead

    James Mead June 26th, 2019 @ 02:36 PM

    • State changed from “new” to “resolved”

    For a long time now issues have been managed on the GitHub repo 1; I'm just doing some tidying up.

    This doesn't appear to be a problem in JRuby v9.2.7, so I'm going to mark this ticket as resolved.

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป

A mocking & stubbing library for Ruby.

* <a href="http://github.com/floehopper/mocha">GitHub repository</a>
* <a href="http://mocha.rubyforge.org">Documentation</a>
* <a href="http://groups.google.com/group/mocha-developer">Mailing List</a>

People watching this ticket