Skip to content

Commit 45dd37f

Browse files
committed
Failing tests for using temp file
1 parent 914ed14 commit 45dd37f

1 file changed

Lines changed: 35 additions & 21 deletions

File tree

test/docx/test_saving.rb

Lines changed: 35 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,35 @@
1-
require 'docx'
2-
require 'test/unit'
3-
4-
class SaveTest < Test::Unit::TestCase
5-
def setup
6-
@doc = Docx::Document.open('test/fixtures/saving.docx')
7-
end
8-
9-
def test_saving
10-
@new_doc_path = 'test/fixtures/new_save.docx'
11-
@doc.save('test/fixtures/new_save.docx')
12-
@new_doc = Docx::Document.open('test/fixtures/saving.docx')
13-
assert_equal @doc.paragraphs.size, @new_doc.paragraphs.size
14-
end
15-
16-
def teardown
17-
if @new_doc and @new_doc_path
18-
File.delete(@new_doc_path)
19-
end
20-
end
21-
end
1+
require 'docx'
2+
require 'test/unit'
3+
require 'tempfile'
4+
5+
class SaveTest < Test::Unit::TestCase
6+
def setup
7+
@doc = Docx::Document.open('test/fixtures/saving.docx')
8+
end
9+
10+
def test_saving
11+
@new_doc_path = 'test/fixtures/new_save.docx'
12+
@doc.save('test/fixtures/new_save.docx')
13+
@new_doc = Docx::Document.open('test/fixtures/saving.docx')
14+
assert_equal @doc.paragraphs.size, @new_doc.paragraphs.size
15+
end
16+
17+
def test_saving_to_tempfile
18+
temp_file = Tempfile.new(['docx_gem', '.docx'])
19+
@new_doc_path = temp_file.path
20+
@doc.save(@new_doc_path)
21+
@new_doc = Docx::Document.open(@new_doc_path)
22+
assert_equal @doc.paragraphs.size, @new_doc.paragraphs.size
23+
24+
temp_file.close
25+
temp_file.unlink
26+
# ensure temp file is gone
27+
assert equal(nil, File.exists?(@new_doc_path))
28+
end
29+
30+
def teardown
31+
if @new_doc and @new_doc_path
32+
File.delete(@new_doc_path)
33+
end
34+
end
35+
end

0 commit comments

Comments
 (0)