Skip to content

Commit

Permalink
Add specs for IO.open to close the file descriptor if block raises
Browse files Browse the repository at this point in the history
It did have some checks if the close operation raises, but not what
happens if the block itself raises an exception.
  • Loading branch information
herwinw committed Sep 25, 2023
1 parent ee83ee6 commit 0ae44d9
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 0ae44d9

Please sign in to comment.