From f3b347e109f42f53ffc30f9e6e10be4b4f285916 Mon Sep 17 00:00:00 2001 From: eregon Date: Fri, 17 Aug 2018 11:22:30 +0000 Subject: Add version guards for Enumerator::ArithmeticSequence * And keep specs for older versions. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64411 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- spec/ruby/core/numeric/shared/step.rb | 19 ++++++++++------ spec/ruby/core/numeric/step_spec.rb | 41 +++++++++++++++++++++++++---------- 2 files changed, 42 insertions(+), 18 deletions(-) (limited to 'spec/ruby/core/numeric') diff --git a/spec/ruby/core/numeric/shared/step.rb b/spec/ruby/core/numeric/shared/step.rb index f058c64a50..0fb2336bf5 100644 --- a/spec/ruby/core/numeric/shared/step.rb +++ b/spec/ruby/core/numeric/shared/step.rb @@ -258,19 +258,24 @@ describe :numeric_step, :shared => true do end describe "when no block is given" do - it "returns an Enumerator when step is 0" do - 1.send(@method, *@step_args.call(2, 0)).should be_an_instance_of(Enumerator::ArithmeticSequence) + step_enum_class = Enumerator + ruby_version_is "2.6" do + step_enum_class = Enumerator::ArithmeticSequence end - it "returns an Enumerator when not passed a block and self > stop" do - 1.send(@method, *@step_args.call(0, 2)).should be_an_instance_of(Enumerator::ArithmeticSequence) + it "returns an #{step_enum_class} when step is 0" do + 1.send(@method, *@step_args.call(2, 0)).should be_an_instance_of(step_enum_class) end - it "returns an Enumerator when not passed a block and self < stop" do - 1.send(@method, *@step_args.call(2, 3)).should be_an_instance_of(Enumerator::ArithmeticSequence) + it "returns an #{step_enum_class} when not passed a block and self > stop" do + 1.send(@method, *@step_args.call(0, 2)).should be_an_instance_of(step_enum_class) end - it "returns an Enumerator that uses the given step" do + it "returns an #{step_enum_class} when not passed a block and self < stop" do + 1.send(@method, *@step_args.call(2, 3)).should be_an_instance_of(step_enum_class) + end + + it "returns an #{step_enum_class} that uses the given step" do 0.send(@method, *@step_args.call(5, 2)).to_a.should eql [0, 2, 4] end diff --git a/spec/ruby/core/numeric/step_spec.rb b/spec/ruby/core/numeric/step_spec.rb index 54133f8810..1eb91aa1e5 100644 --- a/spec/ruby/core/numeric/step_spec.rb +++ b/spec/ruby/core/numeric/step_spec.rb @@ -22,24 +22,43 @@ describe "Numeric#step" do it_behaves_like :numeric_step, :step describe "when no block is given" do - it "returns an Enumerator when step is 0" do - 1.step(5, 0).should be_an_instance_of(Enumerator::ArithmeticSequence) + step_enum_class = Enumerator + ruby_version_is "2.6" do + step_enum_class = Enumerator::ArithmeticSequence end - it "returns an Enumerator when step is 0.0" do - 1.step(2, 0.0).should be_an_instance_of(Enumerator::ArithmeticSequence) + it "returns an #{step_enum_class} when step is 0" do + 1.step(5, 0).should be_an_instance_of(step_enum_class) end - describe "returned Enumerator" do + it "returns an #{step_enum_class} when step is 0.0" do + 1.step(2, 0.0).should be_an_instance_of(step_enum_class) + end + + describe "returned #{step_enum_class}" do describe "size" do - it "raises an ArgumentError when step is 0" do - enum = 1.step(5, 0) - enum.size.should == Float::INFINITY + ruby_version_is ""..."2.6" do + it "raises an ArgumentError when step is 0" do + enum = 1.step(5, 0) + lambda { enum.size }.should raise_error(ArgumentError) + end + + it "raises an ArgumentError when step is 0.0" do + enum = 1.step(2, 0.0) + lambda { enum.size }.should raise_error(ArgumentError) + end end - it "raises an ArgumentError when step is 0.0" do - enum = 1.step(2, 0.0) - enum.size.should == Float::INFINITY + ruby_version_is "2.6" do + it "is infinity when step is 0" do + enum = 1.step(5, 0) + enum.size.should == Float::INFINITY + end + + it "is infinity when step is 0.0" do + enum = 1.step(2, 0.0) + enum.size.should == Float::INFINITY + end end end end -- cgit v1.2.3