aboutsummaryrefslogtreecommitdiffstats
path: root/spec/ruby/core/hash/shared/each.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/ruby/core/hash/shared/each.rb')
-rw-r--r--spec/ruby/core/hash/shared/each.rb21
1 files changed, 21 insertions, 0 deletions
diff --git a/spec/ruby/core/hash/shared/each.rb b/spec/ruby/core/hash/shared/each.rb
index 04a26b5c45..b2483c8116 100644
--- a/spec/ruby/core/hash/shared/each.rb
+++ b/spec/ruby/core/hash/shared/each.rb
@@ -54,6 +54,27 @@ describe :hash_each, shared: true do
end
end
+ it "yields an Array of 2 elements when given a callable of arity 1" 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]]
+ end
+
+ it "raises an error for a Hash when an arity enforcing callable of arity >2 is passed in" do
+ obj = Object.new
+ def obj.foo(key, value, extra)
+ end
+
+ -> {
+ { "a" => 1 }.send(@method, &obj.method(:foo))
+ }.should raise_error(ArgumentError)
+ end
+
it "uses the same order as keys() and values()" do
h = { a: 1, b: 2, c: 3, d: 5 }
keys = []