Skip to content

Commit a07bd8d

Browse files
+spec
1 parent 3a3c850 commit a07bd8d

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

lib/docx/document.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def initialize(path_or_io, options = {})
2525

2626
# if path-or_io is string && does not contain a null byte
2727
if (path_or_io.instance_of?(String) && !/\u0000/.match?(path_or_io))
28-
raise Errno::EIO.new('invalid file format') if !File.extname(path_or_io).eql?('.docx')
28+
raise Errno::EIO.new('Invalid file format') if !File.extname(path_or_io).eql?('.docx')
2929
@zip = Zip::File.open(path_or_io)
3030
else
3131
@zip = Zip::File.open_buffer(path_or_io)

spec/docx/document_spec.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,21 @@
1818
end.to_not raise_error
1919
end
2020
end
21+
22+
context 'When reading a un-supported file' do
23+
it 'should throw file not supported error' do
24+
expect do
25+
Docx::Document.open(@fixtures_path + '/invalid_format.pdf')
26+
end.to raise_error(Errno::EIO, 'Input/output error - Invalid file format')
27+
end
28+
29+
it 'should throw file not found error' do
30+
expect do
31+
invalid_path = @fixtures_path + '/invalid_file_path.docx'
32+
Docx::Document.open(invalid_path)
33+
end.to raise_error(Zip::Error, "File #{invalid_path} not found")
34+
end
35+
end
2136
end
2237

2338
describe 'reading' do

0 commit comments

Comments
 (0)