diff options
Diffstat (limited to 'spec/ruby/core/numeric/step_spec.rb')
-rw-r--r-- | spec/ruby/core/numeric/step_spec.rb | 115 |
1 files changed, 7 insertions, 108 deletions
diff --git a/spec/ruby/core/numeric/step_spec.rb b/spec/ruby/core/numeric/step_spec.rb index 2773000229..1705fb1b4e 100644 --- a/spec/ruby/core/numeric/step_spec.rb +++ b/spec/ruby/core/numeric/step_spec.rb @@ -21,47 +21,10 @@ describe "Numeric#step" do it_behaves_like :numeric_step, :step describe "when no block is given" do - step_enum_class = Enumerator - ruby_version_is "2.6" do - step_enum_class = Enumerator::ArithmeticSequence - end - - ruby_version_is ""..."3.0" do - it "returns an #{step_enum_class} when step is 0" do - 1.step(5, 0).should be_an_instance_of(step_enum_class) - end - - 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 - end + step_enum_class = Enumerator::ArithmeticSequence describe "returned #{step_enum_class}" do describe "size" do - ruby_version_is ""..."2.6" do - it "raises an ArgumentError when step is 0" do - enum = 1.step(5, 0) - -> { enum.size }.should raise_error(ArgumentError) - end - - it "raises an ArgumentError when step is 0.0" do - enum = 1.step(2, 0.0) - -> { enum.size }.should raise_error(ArgumentError) - end - end - - ruby_version_is "2.6"..."3.0" 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 - it "defaults to an infinite size" do enum = 1.step enum.size.should == Float::INFINITY @@ -69,40 +32,15 @@ describe "Numeric#step" do end describe "type" do - ruby_version_is ""..."2.6" do - it "returns an instance of Enumerator" do - 1.step(10).class.should == Enumerator - end - end - - ruby_version_is "2.6" do - it "returns an instance of Enumerator::ArithmeticSequence" do - 1.step(10).class.should == Enumerator::ArithmeticSequence - end + it "returns an instance of Enumerator::ArithmeticSequence" do + 1.step(10).class.should == Enumerator::ArithmeticSequence end end end end - end describe 'with keyword arguments' do - ruby_version_is ""..."3.0" do - it "doesn't raise an error when step is 0" do - -> { 1.step(to: 5, by: 0) { break } }.should_not raise_error - end - - it "doesn't raise an error when step is 0.0" do - -> { 1.step(to: 2, by: 0.0) { break } }.should_not raise_error - end - - it "should loop over self when step is 0 or 0.0" do - 1.step(to: 2, by: 0.0).take(5).should eql [1.0, 1.0, 1.0, 1.0, 1.0] - 1.step(to: 2, by: 0).take(5).should eql [1, 1, 1, 1, 1] - 1.1.step(to: 2, by: 0).take(5).should eql [1.1, 1.1, 1.1, 1.1, 1.1] - end - end - describe "when no block is given" do describe "returned Enumerator" do describe "size" do @@ -110,16 +48,6 @@ describe "Numeric#step" do 1.step(by: 42).size.should == infinity_value end - ruby_version_is ""..."3.0" do - it "should return infinity_value when step is 0" do - 1.step(to: 5, by: 0).size.should == infinity_value - end - - it "should return infinity_value when step is 0.0" do - 1.step(to: 2, by: 0.0).size.should == infinity_value - end - end - it "should return infinity_value when ascending towards a limit of Float::INFINITY" do 1.step(to: Float::INFINITY, by: 42).size.should == infinity_value end @@ -152,24 +80,12 @@ describe "Numeric#step" do end describe 'with mixed arguments' do - ruby_version_is ""..."3.0" do - it "doesn't raise an error when step is 0" do - -> { 1.step(5, by: 0) { break } }.should_not raise_error - end - - it "doesn't raise an error when step is 0.0" do - -> { 1.step(2, by: 0.0) { break } }.should_not raise_error - end + it " raises an ArgumentError when step is 0" do + -> { 1.step(5, by: 0) { break } }.should raise_error(ArgumentError) end - ruby_version_is "3.0" do - it " raises an ArgumentError when step is 0" do - -> { 1.step(5, by: 0) { break } }.should raise_error(ArgumentError) - end - - it "raises an ArgumentError when step is 0.0" do - -> { 1.step(2, by: 0.0) { break } }.should raise_error(ArgumentError) - end + it "raises an ArgumentError when step is 0.0" do + -> { 1.step(2, by: 0.0) { break } }.should raise_error(ArgumentError) end it "raises a ArgumentError when limit and to are defined" do @@ -180,26 +96,9 @@ describe "Numeric#step" do -> { 1.step(5, 1, by: 5) { break } }.should raise_error(ArgumentError) end - ruby_version_is ""..."3.0" do - it "should loop over self when step is 0 or 0.0" do - 1.step(2, by: 0.0).take(5).should eql [1.0, 1.0, 1.0, 1.0, 1.0] - 1.step(2, by: 0).take(5).should eql [1, 1, 1, 1, 1] - 1.1.step(2, by: 0).take(5).should eql [1.1, 1.1, 1.1, 1.1, 1.1] - end - end - describe "when no block is given" do describe "returned Enumerator" do describe "size" do - ruby_version_is ""..."3.0" do - it "should return infinity_value when step is 0" do - 1.step(5, by: 0).size.should == infinity_value - end - - it "should return infinity_value when step is 0.0" do - 1.step(2, by: 0.0).size.should == infinity_value - end - end end end end |