|
10 | 10 | describe Mindee::Input::Source do |
11 | 11 | context 'An image input file' do |
12 | 12 | it 'should load a JPEG from a path' do |
13 | | - input = Mindee::Input::Source::PathInputSource.new(File.join(DATA_DIR, 'file_types/receipt.jpg')) |
14 | | - expect(input.file_mimetype).to eq('image/jpeg') |
| 13 | + input_source = Mindee::Input::Source::PathInputSource.new( |
| 14 | + File.join(DATA_DIR, 'file_types/receipt.jpg') |
| 15 | + ) |
| 16 | + expect(input_source.file_mimetype).to eq('image/jpeg') |
| 17 | + expect(input_source.page_count).to eq(1) |
| 18 | + expect(input_source.pdf?).to eq(false) |
15 | 19 |
|
16 | | - input = Mindee::Input::Source::PathInputSource.new(File.join(DATA_DIR, 'file_types/receipt.jpga')) |
17 | | - expect(input.file_mimetype).to eq('image/jpeg') |
| 20 | + input_source = Mindee::Input::Source::PathInputSource.new( |
| 21 | + File.join(DATA_DIR, 'file_types/receipt.jpga') |
| 22 | + ) |
| 23 | + expect(input_source.file_mimetype).to eq('image/jpeg') |
| 24 | + expect(input_source.page_count).to eq(1) |
| 25 | + expect(input_source.pdf?).to eq(false) |
18 | 26 | end |
19 | 27 |
|
20 | 28 | it 'should load a TIFF from a path' do |
21 | | - input = Mindee::Input::Source::PathInputSource.new(File.join(DATA_DIR, 'file_types/receipt.tif')) |
22 | | - expect(input.file_mimetype).to eq('image/tiff') |
| 29 | + input_source = Mindee::Input::Source::PathInputSource.new( |
| 30 | + File.join(DATA_DIR, 'file_types/receipt.tif') |
| 31 | + ) |
| 32 | + expect(input_source.file_mimetype).to eq('image/tiff') |
| 33 | + expect(input_source.page_count).to eq(1) |
| 34 | + expect(input_source.pdf?).to eq(false) |
23 | 35 |
|
24 | | - input = Mindee::Input::Source::PathInputSource.new(File.join(DATA_DIR, 'file_types/receipt.tiff')) |
25 | | - expect(input.file_mimetype).to eq('image/tiff') |
| 36 | + input_source = Mindee::Input::Source::PathInputSource.new( |
| 37 | + File.join(DATA_DIR, 'file_types/receipt.tiff') |
| 38 | + ) |
| 39 | + expect(input_source.file_mimetype).to eq('image/tiff') |
| 40 | + expect(input_source.page_count).to eq(1) |
| 41 | + expect(input_source.pdf?).to eq(false) |
26 | 42 | end |
27 | 43 |
|
28 | 44 | it 'should load a HEIC from a path' do |
29 | | - input = Mindee::Input::Source::PathInputSource.new(File.join(DATA_DIR, 'file_types/receipt.heic')) |
30 | | - expect(input.file_mimetype).to eq('image/heic') |
| 45 | + input_source = Mindee::Input::Source::PathInputSource.new( |
| 46 | + File.join(DATA_DIR, 'file_types/receipt.heic') |
| 47 | + ) |
| 48 | + expect(input_source.file_mimetype).to eq('image/heic') |
| 49 | + expect(input_source.page_count).to eq(1) |
| 50 | + expect(input_source.pdf?).to eq(false) |
31 | 51 | end |
32 | 52 | end |
33 | 53 |
|
34 | 54 | context 'A PDF input file' do |
35 | 55 | it 'should load a multi-page PDF from a path' do |
36 | | - input = Mindee::Input::Source::PathInputSource.new(File.join(DATA_DIR, 'products/invoices/invoice.pdf')) |
37 | | - expect(input.file_mimetype).to eq('application/pdf') |
38 | | - expect(input.pdf?).to eq(true) |
| 56 | + input_source = Mindee::Input::Source::PathInputSource.new( |
| 57 | + File.join(DATA_DIR, 'products/invoices/invoice.pdf') |
| 58 | + ) |
| 59 | + expect(input_source.file_mimetype).to eq('application/pdf') |
| 60 | + expect(input_source.page_count).to eq(2) |
| 61 | + expect(input_source.pdf?).to eq(true) |
39 | 62 |
|
40 | | - input = Mindee::Input::Source::PathInputSource.new(File.join(DATA_DIR, 'products/invoices/invoice.pdf')) |
41 | | - expect(input.file_mimetype).to eq('application/pdf') |
42 | | - expect(input.pdf?).to eq(true) |
| 63 | + input_source = Mindee::Input::Source::PathInputSource.new( |
| 64 | + File.join(DATA_DIR, 'products/invoices/invoice.pdf') |
| 65 | + ) |
| 66 | + expect(input_source.file_mimetype).to eq('application/pdf') |
| 67 | + expect(input_source.page_count).to eq(2) |
| 68 | + expect(input_source.pdf?).to eq(true) |
43 | 69 |
|
44 | | - input = Mindee::Input::Source::PathInputSource.new(File.join(DATA_DIR, 'products/invoices/invoice_10p.pdf')) |
45 | | - expect(input.file_mimetype).to eq('application/pdf') |
46 | | - expect(input.pdf?).to eq(true) |
47 | | - |
48 | | - input = Mindee::Input::Source::PathInputSource.new(File.join(DATA_DIR, 'products/invoices/invoice_10p.pdf')) |
49 | | - expect(input.file_mimetype).to eq('application/pdf') |
50 | | - expect(input.pdf?).to eq(true) |
| 70 | + input_source = Mindee::Input::Source::PathInputSource.new( |
| 71 | + File.join(DATA_DIR, 'products/invoices/invoice_10p.pdf') |
| 72 | + ) |
| 73 | + expect(input_source.file_mimetype).to eq('application/pdf') |
| 74 | + expect(input_source.page_count).to eq(10) |
| 75 | + expect(input_source.pdf?).to eq(true) |
51 | 76 | end |
52 | 77 | end |
53 | 78 |
|
54 | 79 | context 'A broken fixable PDF' do |
55 | 80 | mindee_client = Mindee::Client.new(api_key: 'invalid-api-key') |
56 | 81 | it 'Should not raise a mime error' do |
57 | 82 | expect do |
58 | | - mindee_client.source_from_path("#{DATA_DIR}/file_types/pdf/broken_fixable.pdf", repair_pdf: true) |
| 83 | + mindee_client.source_from_path( |
| 84 | + "#{DATA_DIR}/file_types/pdf/broken_fixable.pdf", repair_pdf: true |
| 85 | + ) |
59 | 86 | end.not_to raise_error |
60 | 87 | end |
61 | 88 | end |
|
64 | 91 | mindee_client = Mindee::Client.new(api_key: 'invalid-api-key') |
65 | 92 | it 'Should raise an error' do |
66 | 93 | expect do |
67 | | - mindee_client.source_from_path("#{DATA_DIR}/file_types/pdf/broken_unfixable.pdf", repair_pdf: true) |
| 94 | + mindee_client.source_from_path( |
| 95 | + "#{DATA_DIR}/file_types/pdf/broken_unfixable.pdf", repair_pdf: true |
| 96 | + ) |
68 | 97 | end.to raise_error Mindee::Errors::MindeePDFError |
69 | 98 | end |
70 | 99 | end |
|
0 commit comments