File tree Expand file tree Collapse file tree 2 files changed +16
-1
lines changed Expand file tree Collapse file tree 2 files changed +16
-1
lines changed Original file line number Diff line number Diff 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 )
Original file line number Diff line number Diff line change 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
You can’t perform that action at this time.
0 commit comments