File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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
You can’t perform that action at this time.
0 commit comments