Skip to content

Commit

Permalink
Add Specs for transform keys with hash argument
Browse files Browse the repository at this point in the history
Covering "Hash#transform_keys({old_key: new_key}) from ruby#823

Hash#transform_keys and Hash#transform_keys! now accept a hash that maps
keys to new keys. [Feature #16274]
  • Loading branch information
JuanCrg90 committed Oct 7, 2021
1 parent 9597d4b commit 7840ff9
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions core/hash/transform_keys_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down

0 comments on commit 7840ff9

Please sign in to comment.