summaryrefslogtreecommitdiff
path: root/spec/ruby/core/range
diff options
context:
space:
mode:
authorBenoit Daloze <eregontp@gmail.com>2023-02-27 21:02:44 +0100
committerBenoit Daloze <eregontp@gmail.com>2023-02-27 21:02:44 +0100
commit18b4def471bb901d0baa4a1307185484cb05815f (patch)
tree779b24566144e9ee06c6f8de35bd2f7fd74ccdb4 /spec/ruby/core/range
parentde60139053fa7c561858c5c5556d61c82f361dd9 (diff)
Update to ruby/spec@e7dc804
Diffstat (limited to 'spec/ruby/core/range')
-rw-r--r--spec/ruby/core/range/step_spec.rb7
1 files changed, 7 insertions, 0 deletions
diff --git a/spec/ruby/core/range/step_spec.rb b/spec/ruby/core/range/step_spec.rb
index 61ddc5205d..9024636d55 100644
--- a/spec/ruby/core/range/step_spec.rb
+++ b/spec/ruby/core/range/step_spec.rb
@@ -474,10 +474,14 @@ describe "Range#step" do
end
end
+ # We use .take below to ensure the enumerator works
+ # because that's an Enumerable method and so it uses the Enumerator behavior
+ # not just a method overridden in Enumerator::ArithmeticSequence.
describe "type" do
context "when both begin and end are numerics" do
it "returns an instance of Enumerator::ArithmeticSequence" do
(1..10).step.class.should == Enumerator::ArithmeticSequence
+ (1..10).step(3).take(4).should == [1, 4, 7, 10]
end
end
@@ -490,10 +494,12 @@ describe "Range#step" do
context "when range is endless" do
it "returns an instance of Enumerator::ArithmeticSequence when begin is numeric" do
(1..).step.class.should == Enumerator::ArithmeticSequence
+ (1..).step(2).take(3).should == [1, 3, 5]
end
it "returns an instance of Enumerator when begin is not numeric" do
("a"..).step.class.should == Enumerator
+ ("a"..).step(2).take(3).should == %w[a c e]
end
end
@@ -506,6 +512,7 @@ describe "Range#step" do
context "when begin and end are not numerics" do
it "returns an instance of Enumerator" do
("a".."z").step.class.should == Enumerator
+ ("a".."z").step(3).take(4).should == %w[a d g j]
end
end
end