aboutsummaryrefslogtreecommitdiffstats
path: root/spec/ruby/core/enumerable
diff options
context:
space:
mode:
authorBenoit Daloze <eregontp@gmail.com>2020-12-27 17:35:32 +0100
committerBenoit Daloze <eregontp@gmail.com>2020-12-27 17:35:32 +0100
commit727c97da1977544c91b9b3677811da3a44af7d53 (patch)
tree4f027117edad10789db57ff4b83242753a89e39d /spec/ruby/core/enumerable
parent267bed0cd91711e2a8c79219e97431ba22137b01 (diff)
downloadruby-727c97da1977544c91b9b3677811da3a44af7d53.tar.gz
Update to ruby/spec@4ce9f41
Diffstat (limited to 'spec/ruby/core/enumerable')
-rw-r--r--spec/ruby/core/enumerable/first_spec.rb2
-rw-r--r--spec/ruby/core/enumerable/shared/collect.rb27
2 files changed, 27 insertions, 2 deletions
diff --git a/spec/ruby/core/enumerable/first_spec.rb b/spec/ruby/core/enumerable/first_spec.rb
index 1398807fa7..ed1ba599b4 100644
--- a/spec/ruby/core/enumerable/first_spec.rb
+++ b/spec/ruby/core/enumerable/first_spec.rb
@@ -17,7 +17,7 @@ describe "Enumerable#first" do
EnumerableSpecs::YieldsMixed2.new.to_enum.first.should == nil
end
- it "raises a RangeError when passed an Integer" do
+ it "raises a RangeError when passed a Bignum" do
enum = EnumerableSpecs::Empty.new
-> { enum.first(bignum_value) }.should raise_error(RangeError)
end
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