summaryrefslogtreecommitdiff
path: root/spec/ruby/core/array/reject_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/ruby/core/array/reject_spec.rb')
-rw-r--r--spec/ruby/core/array/reject_spec.rb25
1 files changed, 25 insertions, 0 deletions
diff --git a/spec/ruby/core/array/reject_spec.rb b/spec/ruby/core/array/reject_spec.rb
index 77835ef5cd..e6e5e851b6 100644
--- a/spec/ruby/core/array/reject_spec.rb
+++ b/spec/ruby/core/array/reject_spec.rb
@@ -111,6 +111,31 @@ describe "Array#reject!" do
lambda { ArraySpecs.empty_frozen_array.reject! {} }.should raise_error(frozen_error_class)
end
+ it "does not truncate the array is the block raises an exception" do
+ a = [1, 2, 3]
+ begin
+ a.reject! { raise StandardError, 'Oops' }
+ rescue
+ end
+
+ a.should == [1, 2, 3]
+ end
+
+ ruby_version_is "2.4" do
+ it "only removes elements for which the block returns true, keeping the element which raised an error." do
+ a = [1, 2, 3, 4]
+ begin
+ a.reject! do |x|
+ return true if x == 2
+ raise raise StandardError, 'Oops' if x == 3
+ end
+ rescue
+ end
+
+ a.should == [1, 3, 4]
+ end
+ end
+
it_behaves_like :enumeratorize, :reject!
it_behaves_like :enumeratorized_with_origin_size, :reject!, [1,2,3]
it_behaves_like :delete_if, :reject!