Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OpenStruct equality potential bug #2280

solnic opened this issue Dec 5, 2014 · 2 comments

OpenStruct equality potential bug #2280

solnic opened this issue Dec 5, 2014 · 2 comments


Copy link

solnic commented Dec 5, 2014


require 'ostruct'

describe OpenStruct do
  describe '#==' do
    it 'returns true when both are the same' do
      left = 'Jane')
      right = 'Jane')

      expect(left).to eql(right)

RESULT ON MRI 2.1.5p273


Finished in 0.00141 seconds (files took 0.16863 seconds to load)
1 example, 0 failures

RESULT ON JRUBY 1.7.16 (1.9.3p392)



  1) OpenStruct#== returns true when both are the same
     Failure/Error: expect(left).to eql(right)

       expected: #<OpenStruct name="Jane">
            got: #<OpenStruct name="Jane">

       (compared using eql?)

     # ./open_struct_bug.rb:9:in `(root)'

Finished in 0.024 seconds (files took 1.44 seconds to load)
1 example, 1 failure

Failed examples:

rspec ./open_struct_bug.rb:5 # OpenStruct#== returns true when both are the same
Copy link

FWIW, the eql matcher uses eql? for comparisons, not == as your doc string states. Taking RSpec out of the picture, here's the behavior on MRI in IRB:

irb(main):002:0> os1 = "Jane")
=> #<OpenStruct name="Jane">
irb(main):003:0> os2 = "Jane")
=> #<OpenStruct name="Jane">
irb(main):004:0> os1.eql? os2
=> true
irb(main):005:0> os1 == os2
=> true

Compare that to what happens in irb on JRuby:

irb(main):004:0> os1 = "Jane")
=> #<OpenStruct name="Jane">
irb(main):005:0> os2 = "Jane")
=> #<OpenStruct name="Jane">
irb(main):006:0> os1.eql? os2
=> false
irb(main):007:0> os1 == os2
=> true

@enebo enebo added this to the JRuby 1.7.18 milestone Dec 8, 2014
@enebo enebo removed the JRuby 1.7.x label Dec 10, 2014
Copy link

enebo commented Dec 10, 2014

JRuby 1.8 and 1.9 behavior on JRuby 1.7.x matches both 1.8 and 1.9 modes of MRI. MRI 2.0+ changed the behavior of this and master (JRuby 9000) also matches MRI 2.0+. So not fixing to match MRI version compat...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
None yet

No branches or pull requests

4 participants