diff options
author | eregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-10-28 15:15:48 +0000 |
---|---|---|
committer | eregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-10-28 15:15:48 +0000 |
commit | 8c5b60eb22d6d661e87992a65d54e3a5bc0aeed4 (patch) | |
tree | 7905b284cb5b3d62c17ad8a939e339621a498a2c /spec/ruby/core/hash/transform_values_spec.rb | |
parent | 6530b14cee76e2512424d225e64d3c61dd1f6511 (diff) |
Update to ruby/spec@a6b8805
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@60525 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'spec/ruby/core/hash/transform_values_spec.rb')
-rw-r--r-- | spec/ruby/core/hash/transform_values_spec.rb | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/spec/ruby/core/hash/transform_values_spec.rb b/spec/ruby/core/hash/transform_values_spec.rb index 7e4ff45bea..0c9e43d621 100644 --- a/spec/ruby/core/hash/transform_values_spec.rb +++ b/spec/ruby/core/hash/transform_values_spec.rb @@ -24,6 +24,15 @@ ruby_version_is "2.4" do enumerator.each(&:succ).should == { a: 2, b: 3, c: 4 } end end + + it "returns a Hash instance, even on subclasses" do + klass = Class.new(Hash) + h = klass.new + h[:foo] = 42 + r = h.transform_values{|v| 2 * v} + r[:foo].should == 84 + r.class.should == Hash + end end describe "Hash#transform_values!" do @@ -41,6 +50,14 @@ ruby_version_is "2.4" do @hash.should == { a: 2, b: 3, c: 4 } end + it "partially modifies the contents if we broke from the block" do + @hash.transform_values! do |v| + break if v == 3 + 100 + v + end + @hash.should == { a: 101, b: 102, c: 3} + end + context "when no block is given" do it "returns a sized Enumerator" do enumerator = @hash.transform_values! @@ -56,6 +73,10 @@ ruby_version_is "2.4" do @hash.freeze end + it "raises a RuntimeError on an empty hash" do + ->{ {}.freeze.transform_values!(&:succ) }.should raise_error(RuntimeError) + end + it "keeps pairs and raises a RuntimeError" do ->{ @hash.transform_values!(&:succ) }.should raise_error(RuntimeError) @hash.should == @initial_pairs |