diff options
Diffstat (limited to 'spec/ruby/core/array/reject_spec.rb')
| -rw-r--r-- | spec/ruby/core/array/reject_spec.rb | 29 |
1 files changed, 22 insertions, 7 deletions
diff --git a/spec/ruby/core/array/reject_spec.rb b/spec/ruby/core/array/reject_spec.rb index fcf43fabde..8d237b3a75 100644 --- a/spec/ruby/core/array/reject_spec.rb +++ b/spec/ruby/core/array/reject_spec.rb @@ -2,6 +2,7 @@ require_relative '../../spec_helper' require_relative 'fixtures/classes' require_relative 'shared/enumeratorize' require_relative 'shared/delete_if' +require_relative 'shared/iterable_and_tolerating_size_increasing' require_relative '../enumerable/shared/enumeratorized' describe "Array#reject" do @@ -9,9 +10,9 @@ describe "Array#reject" do ary = [1, 2, 3, 4, 5] ary.reject { true }.should == [] ary.reject { false }.should == ary - ary.reject { false }.should_not equal ary + ary.reject { false }.should_not.equal? ary ary.reject { nil }.should == ary - ary.reject { nil }.should_not equal ary + ary.reject { nil }.should_not.equal? ary ary.reject { 5 }.should == [] ary.reject { |i| i < 3 }.should == [3, 4, 5] ary.reject { |i| i % 2 == 0 }.should == [1, 3, 5] @@ -34,7 +35,7 @@ describe "Array#reject" do end it "does not return subclass instance on Array subclasses" do - ArraySpecs::MyArray[1, 2, 3].reject { |x| x % 2 == 0 }.should be_an_instance_of(Array) + ArraySpecs::MyArray[1, 2, 3].reject { |x| x % 2 == 0 }.should.instance_of?(Array) end it "does not retain instance variables" do @@ -47,10 +48,14 @@ describe "Array#reject" do it_behaves_like :enumeratorized_with_origin_size, :reject, [1,2,3] end +describe "Array#reject" do + it_behaves_like :array_iterable_and_tolerating_size_increasing, :reject +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.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] @@ -100,15 +105,20 @@ describe "Array#reject!" do end it "returns an Enumerator if no block given, and the array is frozen" do - ArraySpecs.frozen_array.reject!.should be_an_instance_of(Enumerator) + ArraySpecs.frozen_array.reject!.should.instance_of?(Enumerator) end it "raises a FrozenError on a frozen array" do - -> { ArraySpecs.frozen_array.reject! {} }.should raise_error(FrozenError) + -> { ArraySpecs.frozen_array.reject! {} }.should.raise(FrozenError) end it "raises a FrozenError on an empty frozen array" do - -> { ArraySpecs.empty_frozen_array.reject! {} }.should raise_error(FrozenError) + -> { ArraySpecs.empty_frozen_array.reject! {} }.should.raise(FrozenError) + end + + it "raises a FrozenError on a frozen array only during iteration if called without a block" do + enum = ArraySpecs.frozen_array.reject! + -> { enum.each {} }.should.raise(FrozenError) end it "does not truncate the array is the block raises an exception" do @@ -141,3 +151,8 @@ describe "Array#reject!" do it_behaves_like :enumeratorized_with_origin_size, :reject!, [1,2,3] it_behaves_like :delete_if, :reject! end + +describe "Array#reject!" do + @value_to_return = -> _ { false } + it_behaves_like :array_iterable_and_tolerating_size_increasing, :reject! +end |
