mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Update to ruby/spec@35a9fba
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66888 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
58573c33e4
commit
6204e0804b
147 changed files with 2728 additions and 21522 deletions
17
spec/ruby/core/enumerator/chain/each_spec.rb
Normal file
17
spec/ruby/core/enumerator/chain/each_spec.rb
Normal file
|
@ -0,0 +1,17 @@
|
|||
require_relative '../../../spec_helper'
|
||||
require_relative '../../enumerable/fixtures/classes'
|
||||
|
||||
ruby_version_is "2.6" do
|
||||
describe "Enumerator::Chain#each" do
|
||||
it "calls each on its consistuents as needed" do
|
||||
a = EnumerableSpecs::EachCounter.new(:a, :b)
|
||||
b = EnumerableSpecs::EachCounter.new(:c, :d)
|
||||
|
||||
ScratchPad.record []
|
||||
Enumerator::Chain.new(a, b).each do |elem|
|
||||
ScratchPad << elem << b.times_yielded
|
||||
end
|
||||
ScratchPad.recorded.should == [:a, 0, :b, 0, :c, 1, :d, 2]
|
||||
end
|
||||
end
|
||||
end
|
33
spec/ruby/core/enumerator/chain/initialize_spec.rb
Normal file
33
spec/ruby/core/enumerator/chain/initialize_spec.rb
Normal file
|
@ -0,0 +1,33 @@
|
|||
require_relative '../../../spec_helper'
|
||||
|
||||
ruby_version_is "2.6" do
|
||||
describe "Enumerator::Chain#initialize" do
|
||||
before :each do
|
||||
@uninitialized = Enumerator::Chain.allocate
|
||||
end
|
||||
|
||||
it "is a private method" do
|
||||
Enumerator::Chain.should have_private_instance_method(:initialize, false)
|
||||
end
|
||||
|
||||
it "returns self" do
|
||||
@uninitialized.send(:initialize).should equal(@uninitialized)
|
||||
end
|
||||
|
||||
it "accepts many arguments" do
|
||||
@uninitialized.send(:initialize, 0..1, 2..3, 4..5).should equal(@uninitialized)
|
||||
end
|
||||
|
||||
it "accepts arguments that are not Enumerable nor responding to :each" do
|
||||
@uninitialized.send(:initialize, Object.new).should equal(@uninitialized)
|
||||
end
|
||||
|
||||
describe "on frozen instance" do
|
||||
it "raises a RuntimeError" do
|
||||
lambda {
|
||||
@uninitialized.freeze.send(:initialize)
|
||||
}.should raise_error(RuntimeError)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
16
spec/ruby/core/enumerator/chain/inspect_spec.rb
Normal file
16
spec/ruby/core/enumerator/chain/inspect_spec.rb
Normal file
|
@ -0,0 +1,16 @@
|
|||
require_relative '../../../spec_helper'
|
||||
|
||||
ruby_version_is "2.6" do
|
||||
describe "Enumerator::Chain#inspect" do
|
||||
it "shows a representation of the Enumerator" do
|
||||
Enumerator::Chain.new.inspect.should == "#<Enumerator::Chain: []>"
|
||||
Enumerator::Chain.new(1..2, 3..4).inspect.should == "#<Enumerator::Chain: [1..2, 3..4]>"
|
||||
end
|
||||
|
||||
it "calls inspect on its chain elements" do
|
||||
obj = mock('inspect')
|
||||
obj.should_receive(:inspect).and_return('some desc')
|
||||
Enumerator::Chain.new(obj).inspect.should == "#<Enumerator::Chain: [some desc]>"
|
||||
end
|
||||
end
|
||||
end
|
53
spec/ruby/core/enumerator/chain/rewind_spec.rb
Normal file
53
spec/ruby/core/enumerator/chain/rewind_spec.rb
Normal file
|
@ -0,0 +1,53 @@
|
|||
require_relative '../../../spec_helper'
|
||||
|
||||
ruby_version_is "2.6" do
|
||||
describe "Enumerator::Chain#rewind" do
|
||||
before(:each) do
|
||||
@obj = mock('obj')
|
||||
@obj.should_receive(:each).any_number_of_times.and_yield(42)
|
||||
@second = mock('obj')
|
||||
@second.should_receive(:each).any_number_of_times.and_yield(:second)
|
||||
@enum = Enumerator::Chain.new(@obj, @second)
|
||||
end
|
||||
|
||||
it "returns self" do
|
||||
@enum.rewind.should equal @enum
|
||||
end
|
||||
|
||||
it "does nothing if receiver has not been iterated" do
|
||||
@obj.should_not_receive(:rewind)
|
||||
@obj.respond_to?(:rewind).should == true # sanity check
|
||||
@enum.rewind
|
||||
end
|
||||
|
||||
it "does nothing on objects that don't respond_to rewind" do
|
||||
@obj.respond_to?(:rewind).should == false # sanity check
|
||||
@enum.each {}
|
||||
@enum.rewind
|
||||
end
|
||||
|
||||
it "calls_rewind its objects" do
|
||||
@obj.should_receive(:rewind)
|
||||
@enum.each {}
|
||||
@enum.rewind
|
||||
end
|
||||
|
||||
it "calls_rewind in reverse order" do
|
||||
@obj.should_not_receive(:rewind)
|
||||
@second.should_receive(:rewind).and_raise(RuntimeError)
|
||||
@enum.each {}
|
||||
lambda { @enum.rewind }.should raise_error(RuntimeError)
|
||||
end
|
||||
|
||||
it "calls rewind only for objects that have actually been iterated on" do
|
||||
@obj = mock('obj')
|
||||
@obj.should_receive(:each).any_number_of_times.and_raise(RuntimeError)
|
||||
@enum = Enumerator::Chain.new(@obj, @second)
|
||||
|
||||
@obj.should_receive(:rewind)
|
||||
@second.should_not_receive(:rewind)
|
||||
lambda { @enum.each {} }.should raise_error(RuntimeError)
|
||||
@enum.rewind
|
||||
end
|
||||
end
|
||||
end
|
24
spec/ruby/core/enumerator/chain/size_spec.rb
Normal file
24
spec/ruby/core/enumerator/chain/size_spec.rb
Normal file
|
@ -0,0 +1,24 @@
|
|||
require_relative '../../../spec_helper'
|
||||
require_relative '../../enumerable/fixtures/classes'
|
||||
|
||||
ruby_version_is "2.6" do
|
||||
describe "Enumerator::Chain#size" do
|
||||
it "returns the sum of the sizes of the elements" do
|
||||
a = mock('size')
|
||||
a.should_receive(:size).and_return(40)
|
||||
Enumerator::Chain.new(a, [:a, :b]).size.should == 42
|
||||
end
|
||||
|
||||
it "returns nil or Infinity for the first element of such a size" do
|
||||
[nil, Float::INFINITY].each do |special|
|
||||
a = mock('size')
|
||||
a.should_receive(:size).and_return(40)
|
||||
b = mock('special')
|
||||
b.should_receive(:size).and_return(special)
|
||||
c = mock('not called')
|
||||
c.should_not_receive(:size)
|
||||
Enumerator::Chain.new(a, b, c).size.should == special
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue