Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

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

#84

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.

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

State: resolved
Milestone: none
Assigned to: James Mead James Mead

Activity

  1. James Mead
    James Mead
    • 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.

    February 27th, 2011 @ 08:04 PM

  2. James Mead
    James Mead
    • 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.

    June 26th, 2019 @ 02:36 PM

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.