diff options
author | Benoit Daloze <eregontp@gmail.com> | 2020-03-28 00:22:51 +0100 |
---|---|---|
committer | Benoit Daloze <eregontp@gmail.com> | 2020-03-28 00:22:51 +0100 |
commit | f234d51eaba861edea925eabb564a0bee41b96a0 (patch) | |
tree | 3334f36a91fe81ec704f2980ab169231f52c41d0 /spec/ruby/core/enumerable | |
parent | 296f68816cf575b3ff920f92aec8a4109a7d81d4 (diff) |
Update to ruby/spec@ec84479
Diffstat (limited to 'spec/ruby/core/enumerable')
-rw-r--r-- | spec/ruby/core/enumerable/shared/collect.rb | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/spec/ruby/core/enumerable/shared/collect.rb b/spec/ruby/core/enumerable/shared/collect.rb index 05e94777c7..71b8acd526 100644 --- a/spec/ruby/core/enumerable/shared/collect.rb +++ b/spec/ruby/core/enumerable/shared/collect.rb @@ -34,5 +34,35 @@ describe :enumerable_collect, shared: true do enum.each { |i| -i }.should == [-2, -5, -3, -6, -1, -4] end + it "reports the same arity as the given block" do + entries = [0, 1, 3, 4, 5, 6] + numerous = EnumerableSpecs::Numerous.new(*entries) + + def numerous.each(&block) + ScratchPad << block.arity + super + end + + numerous.send(@method) { |a, b| a % 2 }.should == [0, 1, 1, 0, 1, 0] + ScratchPad.recorded.should == [2] + ScratchPad.clear + ScratchPad.record [] + numerous.send(@method) { |i| i }.should == entries + ScratchPad.recorded.should == [1] + end + + it "yields 2 arguments for a Hash" do + c = Class.new do + def register(a, b) + ScratchPad << [a, b] + end + end + m = c.new.method(:register) + + ScratchPad.record [] + { 1 => 'a', 2 => 'b' }.map(&m) + ScratchPad.recorded.should == [[1, 'a'], [2, 'b']] + end + it_should_behave_like :enumerable_enumeratorized_with_origin_size end |