aboutsummaryrefslogtreecommitdiffstats
path: root/spec/ruby/core/enumerable/shared/collect.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/ruby/core/enumerable/shared/collect.rb')
-rw-r--r--spec/ruby/core/enumerable/shared/collect.rb27
1 files changed, 26 insertions, 1 deletions
diff --git a/spec/ruby/core/enumerable/shared/collect.rb b/spec/ruby/core/enumerable/shared/collect.rb
index 71b8acd526..32c1722c75 100644
--- a/spec/ruby/core/enumerable/shared/collect.rb
+++ b/spec/ruby/core/enumerable/shared/collect.rb
@@ -51,7 +51,20 @@ describe :enumerable_collect, shared: true do
ScratchPad.recorded.should == [1]
end
- it "yields 2 arguments for a Hash" do
+ it "yields an Array of 2 elements for a Hash when block arity is 1" do
+ c = Class.new do
+ def register(a)
+ ScratchPad << a
+ end
+ end
+ m = c.new.method(:register)
+
+ ScratchPad.record []
+ { 1 => 'a', 2 => 'b' }.map(&m)
+ ScratchPad.recorded.should == [[1, 'a'], [2, 'b']]
+ end
+
+ it "yields 2 arguments for a Hash when block arity is 2" do
c = Class.new do
def register(a, b)
ScratchPad << [a, b]
@@ -64,5 +77,17 @@ describe :enumerable_collect, shared: true do
ScratchPad.recorded.should == [[1, 'a'], [2, 'b']]
end
+ it "raises an error for a Hash when an arity enforcing block of arity >2 is passed in" do
+ c = Class.new do
+ def register(a, b, c)
+ end
+ end
+ m = c.new.method(:register)
+
+ -> do
+ { 1 => 'a', 2 => 'b' }.map(&m)
+ end.should raise_error(ArgumentError)
+ end
+
it_should_behave_like :enumerable_enumeratorized_with_origin_size
end