diff options
author | eregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2019-03-28 14:22:29 +0000 |
---|---|---|
committer | eregon <eregon@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2019-03-28 14:22:29 +0000 |
commit | a28aa80c739a1d169649a4da833ef48cfb3465b3 (patch) | |
tree | c2f6bb79c268bd60116b54319ea96f01bb7dda79 /spec/ruby/core/hash | |
parent | 0f64776745ef31e626dec0d42b7fb2a5988397ec (diff) | |
download | ruby-a28aa80c739a1d169649a4da833ef48cfb3465b3.tar.gz |
Update to ruby/spec@e81b3cd
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67361 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'spec/ruby/core/hash')
-rw-r--r-- | spec/ruby/core/hash/shared/each.rb | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/spec/ruby/core/hash/shared/each.rb b/spec/ruby/core/hash/shared/each.rb index bf4c569cfc..1d89cfdd39 100644 --- a/spec/ruby/core/hash/shared/each.rb +++ b/spec/ruby/core/hash/shared/each.rb @@ -1,4 +1,6 @@ describe :hash_each, shared: true do + + # This is inconsistent with below, MRI checks the block arity in rb_hash_each_pair() it "yields a [[key, value]] Array for each pair to a block expecting |*args|" do all_args = [] { 1 => 2, 3 => 4 }.send(@method) { |*args| all_args << args } @@ -19,6 +21,21 @@ describe :hash_each, shared: true do ary.sort.should == ["a", "b", "c"] end + it "yields 2 values and not an Array of 2 elements" do + obj = Object.new + def obj.foo(key, value) + ScratchPad << key << value + end + + ScratchPad.record([]) + { "a" => 1 }.send(@method, &obj.method(:foo)) + ScratchPad.recorded.should == ["a", 1] + + ScratchPad.record([]) + { "a" => 1 }.send(@method, &-> key, value { ScratchPad << key << value }) + ScratchPad.recorded.should == ["a", 1] + end + it "uses the same order as keys() and values()" do h = { a: 1, b: 2, c: 3, d: 5 } keys = [] |