diff options
author | Benoit Daloze <[email protected]> | 2021-10-20 21:41:46 +0200 |
---|---|---|
committer | Benoit Daloze <[email protected]> | 2021-10-20 21:41:46 +0200 |
commit | a6c6eef04aaa075f4bbd0eef740d011737afec91 (patch) | |
tree | e8779ca2ddc044899caabca88c16abc9a9054fff /spec/ruby/core/hash | |
parent | 207a5a5bc13018344dc2ab7913fdcaeaeca01292 (diff) |
Update to ruby/spec@d6921ef
Diffstat (limited to 'spec/ruby/core/hash')
-rw-r--r-- | spec/ruby/core/hash/transform_keys_spec.rb | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/spec/ruby/core/hash/transform_keys_spec.rb b/spec/ruby/core/hash/transform_keys_spec.rb index 70a4cdde36..8ee1a2cd6d 100644 --- a/spec/ruby/core/hash/transform_keys_spec.rb +++ b/spec/ruby/core/hash/transform_keys_spec.rb @@ -42,6 +42,20 @@ describe "Hash#transform_keys" do 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 + + it "allows a partial transformation of keys when using a hash argument" do + @hash.transform_keys({ a: :A, c: :C }).should == { A: 1, b: 2, C: 3 } + end + + it "allows a combination of hash and block argument" do + @hash.transform_keys({ a: :A }, &:to_s).should == { A: 1, 'b' => 2, 'c' => 3 } + end + end end describe "Hash#transform_keys!" do @@ -98,6 +112,13 @@ describe "Hash#transform_keys!" do 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 +133,12 @@ describe "Hash#transform_keys!" do @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) |