Skip to content

Commit ad581ab

Browse files
committed
Fix Hash#assoc spec to avoid a CRuby >= 2.2 bug
* See https://bugs.ruby-lang.org/issues/12855
1 parent fe9e1d1 commit ad581ab

1 file changed

Lines changed: 10 additions & 18 deletions

File tree

core/hash/assoc_spec.rb

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -21,24 +21,16 @@
2121
@h.assoc(:banana).last.should == :yellow
2222
end
2323

24-
ruby_version_is ''...'2.2' do
25-
it "only returns the first matching key-value pair for identity hashes" do
26-
@h.compare_by_identity
27-
@h['pear'] = :red
28-
@h['pear'] = :green
29-
@h.keys.grep(/pear/).size.should == 2
30-
@h.assoc('pear').should == ['pear', :red]
31-
end
32-
end
33-
34-
ruby_version_is '2.2' do
35-
it "only returns the first matching key-value pair for identity hashes" do
36-
@h.compare_by_identity
37-
@h['pear'] = :red
38-
@h['pear'] = :green
39-
@h.keys.grep(/pear/).size.should == 1
40-
@h.assoc('pear').should == ['pear', :green]
41-
end
24+
it "only returns the first matching key-value pair for identity hashes" do
25+
# Avoid literal String keys in Hash#[]= due to https://bugs.ruby-lang.org/issues/12855
26+
h = {}.compare_by_identity
27+
k1 = 'pear'
28+
h[k1] = :red
29+
k2 = 'pear'
30+
h[k2] = :green
31+
h.size.should == 2
32+
h.keys.grep(/pear/).size.should == 2
33+
h.assoc('pear').should == ['pear', :red]
4234
end
4335

4436
it "uses #== to compare the argument to the keys" do

0 commit comments

Comments
 (0)