Skip to content

Commit

Permalink
Add a spec that I would expect to pass
Browse files Browse the repository at this point in the history
eql? should work & Array.uniq should dedupe
  • Loading branch information
kevinterrobang committed Mar 18, 2022
1 parent 5c17f48 commit 3854e5c
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions spec/lib/t/struct/acts_as_comparable_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 3854e5c

Please sign in to comment.