diff options
Diffstat (limited to 'spec/ruby/core/array/each_index_spec.rb')
| -rw-r--r-- | spec/ruby/core/array/each_index_spec.rb | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/spec/ruby/core/array/each_index_spec.rb b/spec/ruby/core/array/each_index_spec.rb index 51af5842c4..b238a89d8a 100644 --- a/spec/ruby/core/array/each_index_spec.rb +++ b/spec/ruby/core/array/each_index_spec.rb @@ -5,7 +5,7 @@ require_relative '../enumerable/shared/enumeratorized' # Modifying a collection while the contents are being iterated # gives undefined behavior. See -# http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-core/23633 +# https://blade.ruby-lang.org/ruby-core/23633 describe "Array#each_index" do before :each do @@ -20,7 +20,7 @@ describe "Array#each_index" do it "returns self" do a = [:a, :b, :c] - a.each_index { |i| }.should equal(a) + a.each_index { |i| }.should.equal?(a) end it "is not confused by removing elements from the front" do @@ -40,3 +40,19 @@ describe "Array#each_index" do it_behaves_like :enumeratorize, :each_index it_behaves_like :enumeratorized_with_origin_size, :each_index, [1,2,3] end + +describe "Array#each_index" do + it "tolerates increasing an array size during iteration" do + array = [:a, :b, :c] + ScratchPad.record [] + i = 0 + + array.each_index do |index| + ScratchPad << index + array << i if i < 100 + i += 1 + end + + ScratchPad.recorded.should == (0..102).to_a # element indices + end +end |
