From 3854e5c2a0a6b24ec9a2eaad46be2444be0328bd Mon Sep 17 00:00:00 2001 From: Kevin Sweeney Date: Fri, 18 Mar 2022 13:53:03 -0700 Subject: [PATCH] Add a spec that I would expect to pass eql? should work & Array.uniq should dedupe --- spec/lib/t/struct/acts_as_comparable_spec.rb | 42 ++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/spec/lib/t/struct/acts_as_comparable_spec.rb b/spec/lib/t/struct/acts_as_comparable_spec.rb index 8228819..5eff54d 100644 --- a/spec/lib/t/struct/acts_as_comparable_spec.rb +++ b/spec/lib/t/struct/acts_as_comparable_spec.rb @@ -183,6 +183,48 @@ class Struct end end end + + describe '#eql?' do + let(:struct_a) do + SorbetStructComparable::Examples::Interest.new( + topic: SorbetStructComparable::Examples::Interest::Topic::Walking, + rating: 10 + ) + end + let(:struct_b) do + SorbetStructComparable::Examples::Interest.new( + topic: SorbetStructComparable::Examples::Interest::Topic::Walking, + rating: 10 + ) + end + + context 'two equal structs' do + it 'should be equal' do + expect(struct_a.eql?(struct_b)).to eq true + end + + it 'should dedupe in an array using uniq' do + expect([struct_a, struct_b].uniq).to match_array([struct_a]) + end + end + + context 'two different structs' do + let(:struct_b) do + SorbetStructComparable::Examples::Interest.new( + topic: SorbetStructComparable::Examples::Interest::Topic::Walking, + rating: 11 + ) + end + + it 'should not be equal' do + expect(struct_a.eql?(struct_b)).to eq false + end + + it 'should not dedupe in an array using uniq' do + expect([struct_a, struct_b].uniq).to match_array([struct_a, struct_b]) + end + end + end end end end