From 0ae44d948d3090253237d523df0145b7398910c4 Mon Sep 17 00:00:00 2001 From: Herwin Date: Mon, 25 Sep 2023 09:25:18 +0200 Subject: [PATCH] Add specs for IO.open to close the file descriptor if block raises It did have some checks if the close operation raises, but not what happens if the block itself raises an exception. --- core/io/open_spec.rb | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/core/io/open_spec.rb b/core/io/open_spec.rb index d3a3961df7..d151da9ce5 100644 --- a/core/io/open_spec.rb +++ b/core/io/open_spec.rb @@ -37,6 +37,19 @@ ScratchPad.recorded.should == :called end + it "propagate an exception in the block after calling #close" do + -> do + IO.open(@fd, "w") do |io| + IOSpecs.io_mock(io, :close) do + super() + ScratchPad.record :called + end + raise Exception + end + end.should raise_error(Exception) + ScratchPad.recorded.should == :called + end + it "propagates an exception raised by #close that is not a StandardError" do -> do IO.open(@fd, "w") do |io|