Sha256: c6cb276eb721873fbe5c2e95d14a197b8ede1c9900503127f38f92175814ad80

Contents?: true

Size: 1.82 KB

Versions: 83

Compression:

Stored size: 1.82 KB

Contents

require File.dirname(File.join(__rhoGetCurrentDir(), __FILE__)) + '/../../spec_helper'
require File.dirname(File.join(__rhoGetCurrentDir(), __FILE__)) + '/fixtures/classes'

describe "Array#delete_at" do
  it "removes the element at the specified index" do
    a = [1, 2, 3, 4]
    a.delete_at(2)
    a.should == [1, 2, 4]
    a.delete_at(-1)
    a.should == [1, 2]
  end

  it "returns the removed element at the specified index" do
    a = [1, 2, 3, 4]
    a.delete_at(2).should == 3
    a.delete_at(-1).should == 4
  end

  it "returns nil and makes no modification if the index is out of range" do
    a = [1, 2]
    a.delete_at(3).should == nil
    a.should == [1, 2]
    a.delete_at(-3).should == nil
    a.should == [1, 2]
  end

  it "tries to convert the passed argument to an Integer using #to_int" do
    obj = mock('to_int')
    obj.should_receive(:to_int).and_return(-1)
    [1, 2].delete_at(obj).should == 2
  end

  it "accepts negative indices" do
    a = [1, 2]
    a.delete_at(-2).should == 1
  end

  ruby_version_is '' ... '1.9' do
    it "raises a TypeError on a frozen array" do
      lambda { [1,2,3].freeze.delete_at(0) }.should raise_error(TypeError)
    end
  end

  ruby_version_is '1.9' do
    it "raises a RuntimeError on a frozen array" do
      lambda { [1,2,3].freeze.delete_at(0) }.should raise_error(RuntimeError)
    end
  end

  it "keeps tainted status" do
    ary = [1, 2]
    ary.taint
    ary.tainted?.should be_true
    ary.delete_at(0)
    ary.tainted?.should be_true
    ary.delete_at(0) # now empty
    ary.tainted?.should be_true
  end

  ruby_version_is '1.9' do
    it "keeps untrusted status" do
      ary = [1, 2]
      ary.untrust
      ary.untrusted?.should be_true
      ary.delete_at(0)
      ary.untrusted?.should be_true
      ary.delete_at(0) # now empty
      ary.untrusted?.should be_true
    end
  end
end

Version data entries

83 entries across 83 versions & 1 rubygems

Version Path
rhodes-3.1.1 spec/framework_spec/app/spec/core/array/delete_at_spec.rb
rhodes-3.1.1.beta spec/framework_spec/app/spec/core/array/delete_at_spec.rb
rhodes-3.1.0 spec/framework_spec/app/spec/core/array/delete_at_spec.rb
rhodes-3.1.0.beta.5 spec/framework_spec/app/spec/core/array/delete_at_spec.rb
rhodes-3.1.0.beta.4 spec/framework_spec/app/spec/core/array/delete_at_spec.rb
rhodes-3.1.0.beta.3 spec/framework_spec/app/spec/core/array/delete_at_spec.rb
rhodes-3.1.0.beta.2 spec/framework_spec/app/spec/core/array/delete_at_spec.rb
rhodes-3.1.0.beta.1 spec/framework_spec/app/spec/core/array/delete_at_spec.rb
rhodes-3.0.2 spec/framework_spec/app/spec/core/array/delete_at_spec.rb
rhodes-3.0.2.beta.1 spec/framework_spec/app/spec/core/array/delete_at_spec.rb
rhodes-3.0.1 spec/framework_spec/app/spec/core/array/delete_at_spec.rb
rhodes-3.0.1.beta.8 spec/framework_spec/app/spec/core/array/delete_at_spec.rb
rhodes-3.0.1.beta.7 spec/framework_spec/app/spec/core/array/delete_at_spec.rb
rhodes-3.0.1.beta.6 spec/framework_spec/app/spec/core/array/delete_at_spec.rb
rhodes-3.0.1.beta.5 spec/framework_spec/app/spec/core/array/delete_at_spec.rb
rhodes-3.0.1.beta.4 spec/framework_spec/app/spec/core/array/delete_at_spec.rb
rhodes-3.0.1.beta.3 spec/framework_spec/app/spec/core/array/delete_at_spec.rb
rhodes-3.0.1.beta.2 spec/framework_spec/app/spec/core/array/delete_at_spec.rb
rhodes-3.0.0 spec/framework_spec/app/spec/core/array/delete_at_spec.rb
rhodes-3.0.0.beta.7 spec/framework_spec/app/spec/core/array/delete_at_spec.rb