Skip to content

Commit

Permalink
Merge pull request #1082 from herwinw/io_open_close_after_exception
Browse files Browse the repository at this point in the history
Add specs for IO.open to close the file descriptor if block raises
  • Loading branch information
andrykonchin authored Sep 25, 2023
2 parents ee83ee6 + 0ae44d9 commit 42ff6ab
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions core/io/open_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand Down

0 comments on commit 42ff6ab

Please sign in to comment.