Skip to content

Commit 7e83dff

Browse files
eregonaycabta
authored andcommitted
Simplify Tempfile.open calls with a block as they now unlink the file automatically
1 parent bfafa52 commit 7e83dff

File tree

3 files changed

+5
-15
lines changed

3 files changed

+5
-15
lines changed

test/rdoc/test_rdoc_parser.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ def test_class_for_executable
106106
def test_class_for_forbidden
107107
omit 'chmod not supported' if Gem.win_platform?
108108

109-
tf = Tempfile.open 'forbidden' do |io|
109+
Tempfile.open 'forbidden' do |io|
110110
begin
111111
File.chmod 0000, io.path
112112
forbidden = @store.add_file io.path
@@ -117,9 +117,7 @@ def test_class_for_forbidden
117117
ensure
118118
File.chmod 0400, io.path
119119
end
120-
io
121120
end
122-
tf.close!
123121
end
124122

125123
def test_class_for_modeline

test/rdoc/test_rdoc_rd_block_parser.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ def test_parse_include_subtree
154154
blank_line,
155155
blank_line)
156156

157-
tf = Tempfile.open %w[parse_include .rd] do |io|
157+
Tempfile.open %w[parse_include .rd] do |io|
158158
io.puts "=begin\ninclude ((*worked*))\n=end"
159159
io.flush
160160

@@ -163,9 +163,7 @@ def test_parse_include_subtree
163163
STR
164164

165165
assert_equal expected, parse(str)
166-
io
167166
end
168-
tf.close!
169167
end
170168

171169
def test_parse_heading

test/rdoc/test_rdoc_rdoc.rb

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -349,16 +349,14 @@ def test_parse_file_encoding
349349
@rdoc.options.encoding = Encoding::ISO_8859_1
350350
@rdoc.store = RDoc::Store.new
351351

352-
tf = Tempfile.open 'test.txt' do |io|
352+
Tempfile.open 'test.txt' do |io|
353353
io.write 'hi'
354354
io.rewind
355355

356356
top_level = @rdoc.parse_file io.path
357357

358358
assert_equal Encoding::ISO_8859_1, top_level.absolute_name.encoding
359-
io
360359
end
361-
tf.close!
362360
end
363361

364362
def test_parse_file_forbidden
@@ -367,7 +365,7 @@ def test_parse_file_forbidden
367365

368366
@rdoc.store = RDoc::Store.new
369367

370-
tf = Tempfile.open 'test.txt' do |io|
368+
Tempfile.open 'test.txt' do |io|
371369
io.write 'hi'
372370
io.rewind
373371

@@ -386,9 +384,7 @@ def test_parse_file_forbidden
386384
ensure
387385
File.chmod 0400, io.path
388386
end
389-
io
390387
end
391-
tf.close!
392388
end
393389

394390
def test_remove_unparseable
@@ -485,7 +481,7 @@ def test_setup_output_dir_exists_empty_created_rid
485481
end
486482

487483
def test_setup_output_dir_exists_file
488-
tf = Tempfile.open 'test_rdoc_rdoc' do |tempfile|
484+
Tempfile.open 'test_rdoc_rdoc' do |tempfile|
489485
path = tempfile.path
490486

491487
e = assert_raise RDoc::Error do
@@ -494,9 +490,7 @@ def test_setup_output_dir_exists_file
494490

495491
assert_match(%r%#{Regexp.escape path} exists and is not a directory%,
496492
e.message)
497-
tempfile
498493
end
499-
tf.close!
500494
end
501495

502496
def test_setup_output_dir_exists_not_rdoc

0 commit comments

Comments
 (0)