From 7840ff970b96a7d64b4868b0e4fb2ca1db81f4d4 Mon Sep 17 00:00:00 2001 From: Juan Carlos Ruiz Date: Wed, 6 Oct 2021 17:47:59 -0500 Subject: [PATCH] Add Specs for transform keys with hash argument Covering "Hash#transform_keys({old_key: new_key}) from #823 Hash#transform_keys and Hash#transform_keys! now accept a hash that maps keys to new keys. [Feature #16274] --- core/hash/transform_keys_spec.rb | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/core/hash/transform_keys_spec.rb b/core/hash/transform_keys_spec.rb index 70a4cdde36..f4f3b02bfa 100644 --- a/core/hash/transform_keys_spec.rb +++ b/core/hash/transform_keys_spec.rb @@ -42,6 +42,12 @@ r.keys.should == [:xfoo] r.class.should == Hash end + + ruby_version_is "3.0" do + it "allows a hash argument" do + @hash.transform_keys({ a: :A, b: :B, c: :C }).should == { A: 1, B: 2, C: 3 } + end + end end describe "Hash#transform_keys!" do @@ -98,6 +104,13 @@ end end + ruby_version_is "3.0" do + it "allows a hash argument" do + @hash.transform_keys!({ a: :A, b: :B, c: :C, d: :D }) + @hash.should == { A: 1, B: 2, C: 3, D: 4 } + end + end + describe "on frozen instance" do before :each do @hash.freeze @@ -112,6 +125,12 @@ @hash.should == @initial_pairs end + ruby_version_is "3.0" do + it "raises a FrozenError on hash argument" do + ->{ @hash.transform_keys!({ a: :A, b: :B, c: :C }) }.should raise_error(FrozenError) + end + end + context "when no block is given" do it "does not raise an exception" do @hash.transform_keys!.should be_an_instance_of(Enumerator)