diff options
Diffstat (limited to 'spec/ruby/core/array/rindex_spec.rb')
| -rw-r--r-- | spec/ruby/core/array/rindex_spec.rb | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/spec/ruby/core/array/rindex_spec.rb b/spec/ruby/core/array/rindex_spec.rb index 175c7bcfe2..858c39dc92 100644 --- a/spec/ruby/core/array/rindex_spec.rb +++ b/spec/ruby/core/array/rindex_spec.rb @@ -4,7 +4,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#rindex" do it "returns the first index backwards from the end where element == to object" do @@ -41,7 +41,7 @@ describe "Array#rindex" do it "properly handles empty recursive arrays" do empty = ArraySpecs.empty_recursive_array empty.rindex(empty).should == 0 - empty.rindex(1).should be_nil + empty.rindex(1).should == nil end it "properly handles recursive arrays" do @@ -68,10 +68,25 @@ describe "Array#rindex" do seen.should == [3] end + it "tolerates increasing an array size during iteration" do + array = [:a, :b, :c] + ScratchPad.record [] + i = 0 + + array.rindex do |e| + ScratchPad << e + array.prepend i if i < 100 + i += 1 + false + end + + ScratchPad.recorded.should == [:c, :a, 1] + end + describe "given no argument and no block" do it "produces an Enumerator" do enum = [4, 2, 1, 5, 1, 3].rindex - enum.should be_an_instance_of(Enumerator) + enum.should.instance_of?(Enumerator) enum.each { |x| x < 2 }.should == 4 end end |
