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

Closed
solnic opened this issue Dec 5, 2014 · 2 comments
Closed

OpenStruct equality potential bug #2280

solnic opened this issue Dec 5, 2014 · 2 comments

Comments

@solnic
Copy link

@solnic solnic commented Dec 5, 2014

TEST

require 'ostruct'

describe OpenStruct do
  describe '#==' do
    it 'returns true when both are the same' do
      left = OpenStruct.new(name: 'Jane')
      right = OpenStruct.new(name: 'Jane')

      expect(left).to eql(right)
    end
  end
end

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)

F

Failures:

  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?)

       Diff:
     # ./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
@myronmarston
Copy link

@myronmarston myronmarston commented Dec 5, 2014

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 = OpenStruct.new(name: "Jane")
=> #<OpenStruct name="Jane">
irb(main):003:0> os2 = OpenStruct.new(name: "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 = OpenStruct.new(name: "Jane")
=> #<OpenStruct name="Jane">
irb(main):005:0> os2 = OpenStruct.new(name: "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
@enebo
Copy link
Member

@enebo 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...

@enebo enebo closed this as completed Dec 10, 2014
@enebo enebo added this to the Invalid or Duplicate milestone Dec 10, 2014
@enebo enebo removed this from the JRuby 1.7.18 milestone Dec 10, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants