Sha256: da76efe3939fcda5a3172ab269a6900fe23dee53793f4f036668579b13b893ca

Contents?: true

Size: 1.36 KB

Versions: 23

Compression:

Stored size: 1.36 KB

Contents

describe "Array#reject" do
  it "returns a new array without elements for which block is true" do
    ary = [1, 2, 3, 4, 5]
    ary.reject { true }.should == []
    ary.reject { false }.should == ary
    ary.reject { false }.object_id.should_not == ary.object_id
    ary.reject { nil }.should == ary
    ary.reject { nil }.object_id.should_not == ary.object_id
    ary.reject { |i| i < 3 }.should == [3, 4, 5]
    ary.reject { |i| i % 2 == 0 }.should == [1, 3, 5]
  end

  it "returns self when called on an Array emptied with #shift" do
    array = [1]
    array.shift
    array.reject { |x| true }.should == []
  end
end

describe "Array#reject!" do
  it "removes elements for which block is true" do
    a = [3, 4, 5, 6, 7, 8, 9, 10, 11]
    a.reject! { |i| i % 2 == 0 }.should equal(a)
    a.should == [3, 5, 7, 9, 11]
    a.reject! { |i| i > 8 }
    a.should == [3, 5, 7]
    a.reject! { |i| i < 4 }
    a.should == [5, 7]
    a.reject! { |i| i == 5 }
    a.should == [7]
    a.reject! { true }
    a.should == []
    a.reject! { true }
    a.should == []
  end

  it "returns nil when called on an array emptied with #shift" do
    array = [1]
    array.shift
    array.reject! { |x| true }.should == nil
  end

  it "returns nil if no changes are made" do
    a = [1, 2, 3]

    a.reject! { |i| i < 0 }.should == nil

    a.reject! { true }
    a.reject! { true }.should == nil
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

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