diff options
Diffstat (limited to 'spec/ruby/core/hash/shared/each.rb')
-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 = [] |