summaryrefslogtreecommitdiff
path: root/test/zlib
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2021-02-03 17:34:41 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2021-02-03 17:34:41 +0900
commitb4eba8dfee50a8b9085b32a1750be5313b9cf96b (patch)
tree665e509dc12d52180ba58ac62c31f670b45c128e /test/zlib
parentd05a268adc402e0a9a5eac0ce291cfd34e68f29a (diff)
Prefer block forms to close opened files
Diffstat (limited to 'test/zlib')
-rw-r--r--test/zlib/test_zlib.rb24
1 files changed, 13 insertions, 11 deletions
diff --git a/test/zlib/test_zlib.rb b/test/zlib/test_zlib.rb
index 42ee5c6638..e6d61ca79f 100644
--- a/test/zlib/test_zlib.rb
+++ b/test/zlib/test_zlib.rb
@@ -510,22 +510,24 @@ if defined? Zlib
gz = Zlib::GzipWriter.new(t)
gz.print("foo")
gz.close
- t = File.open(t.path, 'ab')
- gz = Zlib::GzipWriter.new(t)
- gz.print("bar")
- gz.close
+ File.open(t.path, 'ab') do |f|
+ gz = Zlib::GzipWriter.new(f)
+ gz.print("bar")
+ gz.close
+ end
results = []
- t = File.open(t.path, 'rb')
- Zlib::GzipReader.zcat(t) do |str|
- results << str
+ File.open(t.path, 'rb') do |f|
+ Zlib::GzipReader.zcat(f) do |str|
+ results << str
+ end
end
assert_equal(["foo", "bar"], results)
- t.close
- t = File.open(t.path, 'rb')
- assert_equal("foobar", Zlib::GzipReader.zcat(t))
- t.close
+ results = File.open(t.path, 'rb') do |f|
+ Zlib::GzipReader.zcat(f)
+ end
+ assert_equal("foobar", results)
}
end