Sha256: 2845c40eba056a9847a9d1c5c3838986356be1da6ef6e7874b26c807a3879b32

Contents?: true

Size: 628 Bytes

Versions: 12

Compression:

Stored size: 628 Bytes

Contents

require "spec_helper"

describe "Array#fill" do
  it "returns self" do
    ary = [1, 2, 3]
    ary.fill(:a).should equal(ary)
  end

  it "is destructive" do
    ary = [1, 2, 3]
    ary.fill(:a)
    ary.should == [:a, :a, :a]
  end

  it "replaces all elements in the array with the filler if not given an index nor a length" do
    ary = ['a', 'b', 'c', 'duh']
    ary.fill(8).should == [8, 8, 8, 8]

    str = "x"
    ary.fill(str).should == [str, str, str, str]
  end

  it "replaces all elements with the value of block (index given to block)" do
    [nil, nil, nil, nil].fill { |i| i * 2 }.should == [0, 2, 4, 6]
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
opal-0.4.4 spec/opal/array/fill_spec.rb
opal-0.4.3 spec/opal/array/fill_spec.rb
opal-0.4.2 spec/opal/array/fill_spec.rb
opal-0.4.1 spec/opal/array/fill_spec.rb
opal-0.4.0 spec/opal/array/fill_spec.rb
opal-0.3.44 spec/opal/array/fill_spec.rb
opal-0.3.43 spec/opal/array/fill_spec.rb
opal-0.3.42 spec/core_ext/array/fill_spec.rb
opal-0.3.41 spec/core/array/fill_spec.rb
opal-0.3.40 spec/core/array/fill_spec.rb
opal-0.3.39 spec/core/array/fill_spec.rb
opal-0.3.38 spec/core/array/fill_spec.rb