From eab6c534adb381b81291e871cd57c957cf786503 Mon Sep 17 00:00:00 2001 From: Benoit Daloze Date: Wed, 31 Jul 2019 11:04:35 +0200 Subject: [PATCH] Attempt to fix Hash#rehash spec --- spec/ruby/core/hash/rehash_spec.rb | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/spec/ruby/core/hash/rehash_spec.rb b/spec/ruby/core/hash/rehash_spec.rb index 2af287cd70..1bf4753f4e 100644 --- a/spec/ruby/core/hash/rehash_spec.rb +++ b/spec/ruby/core/hash/rehash_spec.rb @@ -3,23 +3,26 @@ require_relative 'fixtures/classes' describe "Hash#rehash" do it "reorganizes the hash by recomputing all key hash codes" do - k1 = [1] - k2 = [2] + k1 = Object.new + k2 = Object.new + def k1.hash; 0; end + def k2.hash; 1; end + h = {} - h[k1] = 0 - h[k2] = 1 + h[k1] = :v1 + h[k2] = :v2 - k1 << 2 + def k1.hash; 1; end - # if k1 is modified to k1', k1.hash and k1'.hash can be same. - # So this test has an issue. For the present, this line is commented out. - # h.key?(k1).should == false + # The key should no longer be found as the #hash changed. + # Hash values 0 and 1 should not conflict, even with 1-bit stored hash. + h.key?(k1).should == false h.keys.include?(k1).should == true h.rehash.should equal(h) h.key?(k1).should == true - h[k1].should == 0 + h[k1].should == :v1 k1 = mock('k1') k2 = mock('k2')