From 59bdcb4ea95c60159bb2bfc8c73022364da8ec0d Mon Sep 17 00:00:00 2001 From: Herwin Date: Sat, 7 Oct 2023 09:25:28 +0200 Subject: [PATCH] Add test for IO#gets setting $_ to nil after reading all lines --- core/io/gets_spec.rb | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/core/io/gets_spec.rb b/core/io/gets_spec.rb index 73d76b3ab..ca64bf860 100644 --- a/core/io/gets_spec.rb +++ b/core/io/gets_spec.rb @@ -24,6 +24,12 @@ end end + it "sets $_ to nil after the last line has been read" do + while @io.gets + end + $_.should be_nil + end + it "returns nil if called at the end of the stream" do IOSpecs.lines.length.times { @io.gets } @io.gets.should == nil