Sha256: 7f9e641aab5f4609dbb1a51c3bd156cdb52dcc164cc9b02ecb4463317fc9af2a

Contents?: true

Size: 802 Bytes

Versions: 23

Compression:

Stored size: 802 Bytes

Contents

describe "Array#fetch" do
  it "returns the element at the passed index" do
    [1, 2, 3].fetch(1).should == 2
    [nil].fetch(0).should == nil
  end

  it "counts negative indices backwards from end" do
    [1, 2, 3, 4].fetch(-1).should == 4
  end

  it "raises an IndexError id there is no element at index" do
    lambda { [1, 2, 3].fetch(3) }.should raise_error(IndexError)
    lambda { [1, 2, 3].fetch(-4) }.should raise_error(IndexError)
    lambda { [].fetch(0) }.should raise_error(IndexError)
  end

  it "returns default if there is no element at index if passed a default value" do
    [1, 2, 3].fetch(5, :not_found).should == :not_found
    [1, 2, 3].fetch(5, nil).should == nil
    [1, 2, 3].fetch(-4, :not_found).should == :not_found
    [nil].fetch(0, :not_found).should == nil
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
opal-0.3.41 spec/core/array/fetch_spec.rb
opal-0.3.40 spec/core/array/fetch_spec.rb
opal-0.3.39 spec/core/array/fetch_spec.rb
opal-0.3.38 spec/core/array/fetch_spec.rb
opal-0.3.37 spec/core/array/fetch_spec.rb
opal-0.3.36 spec/core/array/fetch_spec.rb
opal-0.3.35 spec/core/array/fetch_spec.rb
opal-0.3.34 spec/core/array/fetch_spec.rb
opal-0.3.33 spec/core/array/fetch_spec.rb
opal-0.3.32 spec/core/array/fetch_spec.rb
opal-0.3.31 spec/core/array/fetch_spec.rb
opal-0.3.30 spec/core/array/fetch_spec.rb
opal-0.3.29 spec/core/array/fetch_spec.rb
opal-0.3.28 spec/core/array/fetch_spec.rb
opal-0.3.27 spec/core/array/fetch_spec.rb
opal-0.3.26 spec/core/array/fetch_spec.rb
opal-0.3.25 spec/core/array/fetch_spec.rb
opal-0.3.22 spec/core/array/fetch_spec.rb
opal-0.3.21 test/core/array/fetch_spec.rb
opal-0.3.20 test/core/array/fetch_spec.rb