libis-tools 0.9.50 → 0.9.51
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/libis/tools/extend/hash.rb +10 -0
- data/lib/libis/tools/version.rb +1 -1
- data/spec/data/test.xlsx +0 -0
- data/spec/spreadsheet_spec.rb +600 -344
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 22a6505236d99f66a0a0f256bd487bca6037be5c
|
4
|
+
data.tar.gz: fa81725c403fb924bee58811d5e9444df990de45
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 02ff95dad22e9461b3d28bec2b37eafb56ca06b7fed6a2a1292b7eb03eea152cf8447f26d5dbe120e0cf3cdb21dcf428a77f708b3c832232a13bb4a597aabbd1
|
7
|
+
data.tar.gz: cad24b04aeb638cfc2aed59d2e7fd3f5038b6081215c89be378503e6b9a39bcdcd2bf106bf951565f34bd0234450916607e0dd9076a3fcbf1677d456f6839f21
|
@@ -39,6 +39,16 @@ class Hash
|
|
39
39
|
end
|
40
40
|
end unless method_defined? :recursive_merge!
|
41
41
|
|
42
|
+
# Merges two hashes with priority for the first hash
|
43
|
+
def reverse_merge(other_hash)
|
44
|
+
self.merge(other_hash) {|_,v, _| v}
|
45
|
+
end unless method_defined? :reverse_merge
|
46
|
+
|
47
|
+
# Merges two hashes in-place with priority for the first hash
|
48
|
+
def reverse_merge!(other_hash)
|
49
|
+
self.merge!(other_hash) {|_,v, _| v}
|
50
|
+
end unless method_defined? :reverse_merge!
|
51
|
+
|
42
52
|
# Convert all keys to symbols. In-place operation.
|
43
53
|
# @param (see #key_strings_to_symbols)
|
44
54
|
def key_strings_to_symbols!(options = {})
|
data/lib/libis/tools/version.rb
CHANGED
data/spec/data/test.xlsx
CHANGED
Binary file
|
data/spec/spreadsheet_spec.rb
CHANGED
@@ -5,7 +5,7 @@ require 'libis/tools/spreadsheet'
|
|
5
5
|
|
6
6
|
describe 'Libis::Tools::Spreadsheet' do
|
7
7
|
|
8
|
-
let(:path) {
|
8
|
+
let(:path) {File.absolute_path('data', File.dirname(__FILE__))}
|
9
9
|
let(:ss) {
|
10
10
|
Libis::Tools::Spreadsheet.new(
|
11
11
|
File.join(path, file_name),
|
@@ -14,18 +14,18 @@ describe 'Libis::Tools::Spreadsheet' do
|
|
14
14
|
)
|
15
15
|
}
|
16
16
|
|
17
|
-
let(:optional_headers) {
|
17
|
+
let(:optional_headers) {[]}
|
18
18
|
|
19
19
|
context 'CSV file' do
|
20
20
|
context 'with headers' do
|
21
|
-
let(:file_name) {
|
21
|
+
let(:file_name) {'test-headers.csv'}
|
22
22
|
|
23
23
|
context 'well-formed' do
|
24
24
|
|
25
|
-
let(:required_headers) {
|
25
|
+
let(:required_headers) {%w'FirstName LastName'}
|
26
26
|
|
27
27
|
it 'opens correctly' do
|
28
|
-
expect{
|
28
|
+
expect {ss}.not_to raise_error
|
29
29
|
end
|
30
30
|
|
31
31
|
it 'contains expected headers' do
|
@@ -60,10 +60,10 @@ describe 'Libis::Tools::Spreadsheet' do
|
|
60
60
|
|
61
61
|
context 'not specified' do
|
62
62
|
|
63
|
-
let(:required_headers) {
|
63
|
+
let(:required_headers) {[]}
|
64
64
|
|
65
65
|
it 'opens correctly' do
|
66
|
-
expect{
|
66
|
+
expect {ss}.not_to raise_error
|
67
67
|
end
|
68
68
|
|
69
69
|
it 'contains expected headers' do
|
@@ -95,23 +95,23 @@ describe 'Libis::Tools::Spreadsheet' do
|
|
95
95
|
|
96
96
|
context 'not well-formed' do
|
97
97
|
|
98
|
-
let(:required_headers) {
|
98
|
+
let(:required_headers) {%w'FirstName LastName address phone'}
|
99
99
|
|
100
100
|
it 'throws error when opened' do
|
101
|
-
expect {
|
101
|
+
expect {ss}.to raise_error(RuntimeError, 'Headers not found: ["phone"].')
|
102
102
|
end
|
103
103
|
end
|
104
104
|
|
105
105
|
end
|
106
106
|
|
107
107
|
context 'without headers' do
|
108
|
-
let(:file_name) {
|
108
|
+
let(:file_name) {'test-noheaders.csv'}
|
109
109
|
|
110
110
|
context 'well-formed and strict' do
|
111
|
-
let(:required_headers) {
|
111
|
+
let(:required_headers) {%w'FirstName LastName'}
|
112
112
|
|
113
113
|
it 'opens correctly' do
|
114
|
-
expect {
|
114
|
+
expect {ss}.not_to raise_error
|
115
115
|
end
|
116
116
|
|
117
117
|
it 'contains only required headers' do
|
@@ -145,11 +145,11 @@ describe 'Libis::Tools::Spreadsheet' do
|
|
145
145
|
end
|
146
146
|
|
147
147
|
context 'well-formed with optional headers' do
|
148
|
-
let(:required_headers) {
|
149
|
-
let(:optional_headers) {
|
148
|
+
let(:required_headers) {%w'FirstName LastName'}
|
149
|
+
let(:optional_headers) {%w'address'}
|
150
150
|
|
151
151
|
it 'opens correctly' do
|
152
|
-
expect {
|
152
|
+
expect {ss}.not_to raise_error
|
153
153
|
end
|
154
154
|
|
155
155
|
it 'contains required and optional headers' do
|
@@ -187,11 +187,11 @@ describe 'Libis::Tools::Spreadsheet' do
|
|
187
187
|
|
188
188
|
context 'missing optional headers' do
|
189
189
|
|
190
|
-
let(:required_headers) {
|
191
|
-
let(:optional_headers) {
|
190
|
+
let(:required_headers) {%w'FirstName LastName address'}
|
191
|
+
let(:optional_headers) {%w'phone'}
|
192
192
|
|
193
193
|
it 'opens correctly' do
|
194
|
-
expect {
|
194
|
+
expect {ss}.not_to raise_error
|
195
195
|
end
|
196
196
|
|
197
197
|
it 'contains only required headers' do
|
@@ -228,10 +228,10 @@ describe 'Libis::Tools::Spreadsheet' do
|
|
228
228
|
end
|
229
229
|
|
230
230
|
context 'missing required header' do
|
231
|
-
let(:required_headers) {
|
231
|
+
let(:required_headers) {%w'FirstName LastName address phone'}
|
232
232
|
|
233
233
|
it 'throws error when opened' do
|
234
|
-
expect {
|
234
|
+
expect {ss}.to raise_error(RuntimeError, 'Sheet does not contain enough columns.')
|
235
235
|
end
|
236
236
|
|
237
237
|
end
|
@@ -241,60 +241,67 @@ describe 'Libis::Tools::Spreadsheet' do
|
|
241
241
|
end
|
242
242
|
|
243
243
|
context 'XLSX file' do
|
244
|
-
|
245
|
-
|
246
|
-
#
|
247
|
-
|
248
|
-
#
|
249
|
-
|
250
|
-
#
|
251
|
-
|
244
|
+
|
245
|
+
let(:real_headers) {%w'Date Amount Code Remark'}
|
246
|
+
# noinspection RubyStringKeysInHashInspection
|
247
|
+
let(:header_row) {{'Date' => 'Date', 'Amount' => 'Amount', 'Code' => 'Code', 'Remark' => 'Remark'}}
|
248
|
+
# noinspection RubyStringKeysInHashInspection
|
249
|
+
let(:first_data_row) {{'Date' => Date.new(2016, 05, 10), 'Amount' => 1270.0, 'Code' => 1, 'Remark' => 'a'}}
|
250
|
+
# noinspection RubyStringKeysInHashInspection
|
251
|
+
let(:data_row_13) {{'Date' => Date.new(2016, 7, 1), 'Amount' => 3705.0, 'Code' => 3, 'Remark' => 'b'}}
|
252
|
+
let(:size_with_headers) { 18 }
|
253
|
+
let(:size_without_headers) { 17 }
|
252
254
|
|
253
255
|
context 'with headers' do
|
254
|
-
let(:file_name) {
|
256
|
+
let(:file_name) {'test.xlsx|Expenses'}
|
255
257
|
|
256
258
|
context 'well-formed' do
|
257
259
|
|
258
|
-
let(:required_headers) {
|
260
|
+
let(:required_headers) {%w'Date Amount'}
|
259
261
|
|
260
262
|
it 'opens correctly' do
|
261
|
-
expect{
|
263
|
+
expect {ss}.not_to raise_error
|
262
264
|
end
|
263
265
|
|
264
266
|
it 'contains expected headers' do
|
265
267
|
required_headers.each do |header|
|
266
268
|
expect(ss.headers).to include header
|
267
269
|
end
|
268
|
-
expect(ss.headers).to eq
|
270
|
+
expect(ss.headers).to eq real_headers
|
271
|
+
end
|
272
|
+
|
273
|
+
it 'each returns header and data rows' do
|
274
|
+
expect(ss.each.count).to eq size_with_headers
|
275
|
+
expect(ss.each.first).to eq header_row
|
269
276
|
end
|
270
277
|
|
271
278
|
it '#shift returns Hash object' do
|
272
279
|
row = ss.shift
|
273
280
|
expect(row).to be_a Hash
|
274
|
-
expect(row['Date']).to eq Date
|
275
|
-
expect(row['Amount']).to eq
|
276
|
-
expect(row['Code']).to eq
|
277
|
-
expect(row['Remark']).to eq '
|
281
|
+
expect(row['Date']).to eq first_data_row['Date']
|
282
|
+
expect(row['Amount']).to eq first_data_row['Amount']
|
283
|
+
expect(row['Code']).to eq first_data_row['Code']
|
284
|
+
expect(row['Remark']).to eq first_data_row['Remark']
|
278
285
|
expect(row['dummy']).to be_nil
|
279
286
|
end
|
280
287
|
|
281
288
|
it '#parse returns Array of Hash objects' do
|
282
289
|
rows = ss.parse
|
283
290
|
expect(rows).to be_a Array
|
284
|
-
expect(rows.size).to eq
|
291
|
+
expect(rows.size).to eq size_without_headers
|
285
292
|
row = rows[0]
|
286
293
|
expect(row).to be_a Hash
|
287
|
-
expect(row['Date']).to eq Date
|
288
|
-
expect(row['Amount']).to eq
|
289
|
-
expect(row['Code']).to eq
|
290
|
-
expect(row['Remark']).to eq '
|
294
|
+
expect(row['Date']).to eq first_data_row['Date']
|
295
|
+
expect(row['Amount']).to eq first_data_row['Amount']
|
296
|
+
expect(row['Code']).to eq first_data_row['Code']
|
297
|
+
expect(row['Remark']).to eq first_data_row['Remark']
|
291
298
|
expect(row['dummy']).to be_nil
|
292
299
|
row = rows[13]
|
293
300
|
expect(row).to be_a Hash
|
294
|
-
expect(row['Date']).to eq Date
|
295
|
-
expect(row['Amount']).to eq
|
296
|
-
expect(row['Code']).to eq
|
297
|
-
expect(row['Remark']).to eq '
|
301
|
+
expect(row['Date']).to eq data_row_13['Date']
|
302
|
+
expect(row['Amount']).to eq data_row_13['Amount']
|
303
|
+
expect(row['Code']).to eq data_row_13['Code']
|
304
|
+
expect(row['Remark']).to eq data_row_13['Remark']
|
298
305
|
expect(row['dummy']).to be_nil
|
299
306
|
end
|
300
307
|
|
@@ -302,46 +309,52 @@ describe 'Libis::Tools::Spreadsheet' do
|
|
302
309
|
|
303
310
|
context 'not specified' do
|
304
311
|
|
305
|
-
let(:required_headers) {
|
312
|
+
let(:required_headers) {[]}
|
313
|
+
|
306
314
|
|
307
315
|
it 'opens correctly' do
|
308
|
-
expect{
|
316
|
+
expect {ss}.not_to raise_error
|
309
317
|
end
|
310
318
|
|
311
319
|
it 'contains expected headers' do
|
312
320
|
required_headers.each do |header|
|
313
321
|
expect(ss.headers).to include header
|
314
322
|
end
|
315
|
-
expect(ss.headers).to eq
|
323
|
+
expect(ss.headers).to eq real_headers
|
324
|
+
end
|
325
|
+
|
326
|
+
it 'each returns header and data rows' do
|
327
|
+
expect(ss.each.count).to eq size_with_headers
|
328
|
+
expect(ss.each.first).to eq header_row
|
316
329
|
end
|
317
330
|
|
318
331
|
it '#shift returns Hash object' do
|
319
332
|
row = ss.shift
|
320
333
|
expect(row).to be_a Hash
|
321
|
-
expect(row['Date']).to eq Date
|
322
|
-
expect(row['Amount']).to eq
|
323
|
-
expect(row['Code']).to eq
|
324
|
-
expect(row['Remark']).to eq '
|
334
|
+
expect(row['Date']).to eq first_data_row['Date']
|
335
|
+
expect(row['Amount']).to eq first_data_row['Amount']
|
336
|
+
expect(row['Code']).to eq first_data_row['Code']
|
337
|
+
expect(row['Remark']).to eq first_data_row['Remark']
|
325
338
|
expect(row['dummy']).to be_nil
|
326
339
|
end
|
327
340
|
|
328
341
|
it '#parse returns Array of Hash objects' do
|
329
342
|
rows = ss.parse
|
330
343
|
expect(rows).to be_a Array
|
331
|
-
expect(rows.size).to eq
|
344
|
+
expect(rows.size).to eq size_without_headers
|
332
345
|
row = rows[0]
|
333
346
|
expect(row).to be_a Hash
|
334
|
-
expect(row['Date']).to eq Date
|
335
|
-
expect(row['Amount']).to eq
|
336
|
-
expect(row['Code']).to eq
|
337
|
-
expect(row['Remark']).to eq '
|
347
|
+
expect(row['Date']).to eq first_data_row['Date']
|
348
|
+
expect(row['Amount']).to eq first_data_row['Amount']
|
349
|
+
expect(row['Code']).to eq first_data_row['Code']
|
350
|
+
expect(row['Remark']).to eq first_data_row['Remark']
|
338
351
|
expect(row['dummy']).to be_nil
|
339
352
|
row = rows[13]
|
340
353
|
expect(row).to be_a Hash
|
341
|
-
expect(row['Date']).to eq Date
|
342
|
-
expect(row['Amount']).to eq
|
343
|
-
expect(row['Code']).to eq
|
344
|
-
expect(row['Remark']).to eq '
|
354
|
+
expect(row['Date']).to eq data_row_13['Date']
|
355
|
+
expect(row['Amount']).to eq data_row_13['Amount']
|
356
|
+
expect(row['Code']).to eq data_row_13['Code']
|
357
|
+
expect(row['Remark']).to eq data_row_13['Remark']
|
345
358
|
expect(row['dummy']).to be_nil
|
346
359
|
end
|
347
360
|
|
@@ -349,37 +362,42 @@ describe 'Libis::Tools::Spreadsheet' do
|
|
349
362
|
|
350
363
|
context 'not well-formed' do
|
351
364
|
|
352
|
-
let(:required_headers) {
|
365
|
+
let(:required_headers) {%w'Date dummy1 Amount dummy2'}
|
353
366
|
|
354
367
|
it 'throws error when opened' do
|
355
|
-
expect {
|
368
|
+
expect {ss}.to raise_error(RuntimeError, 'Headers not found: ["dummy1", "dummy2"].')
|
356
369
|
end
|
357
370
|
end
|
358
371
|
|
359
372
|
end
|
360
373
|
|
361
374
|
context 'without headers' do
|
362
|
-
let(:file_name) {
|
375
|
+
let(:file_name) {'test.xlsx|ExpensesNoHeaders'}
|
363
376
|
|
364
377
|
context 'well-formed and strict' do
|
365
|
-
let(:required_headers) {
|
378
|
+
let(:required_headers) {%w'Date Amount'}
|
366
379
|
|
367
380
|
it 'opens correctly' do
|
368
|
-
expect {
|
381
|
+
expect {ss}.not_to raise_error
|
369
382
|
end
|
370
383
|
|
371
384
|
it 'contains only required headers' do
|
372
385
|
required_headers.each do |header|
|
373
386
|
expect(ss.headers).to include header
|
374
387
|
end
|
375
|
-
expect(ss.headers).to eq
|
388
|
+
expect(ss.headers).to eq required_headers
|
389
|
+
end
|
390
|
+
|
391
|
+
it 'each returns header and data rows' do
|
392
|
+
expect(ss.each.count).to eq size_with_headers
|
393
|
+
expect(ss.each.first.keys).to eq required_headers
|
376
394
|
end
|
377
395
|
|
378
396
|
it '#shift returns Hash object' do
|
379
397
|
row = ss.shift
|
380
398
|
expect(row).to be_a Hash
|
381
|
-
expect(row['Date']).to eq Date
|
382
|
-
expect(row['Amount']).to eq
|
399
|
+
expect(row['Date']).to eq first_data_row['Date']
|
400
|
+
expect(row['Amount']).to eq first_data_row['Amount']
|
383
401
|
expect(row['Code']).to be_nil
|
384
402
|
expect(row['Remark']).to be_nil
|
385
403
|
expect(row['dummy']).to be_nil
|
@@ -388,18 +406,18 @@ describe 'Libis::Tools::Spreadsheet' do
|
|
388
406
|
it '#parse returns Array of Hash objects' do
|
389
407
|
rows = ss.parse
|
390
408
|
expect(rows).to be_a Array
|
391
|
-
expect(rows.size).to eq
|
409
|
+
expect(rows.size).to eq size_without_headers
|
392
410
|
row = rows[0]
|
393
411
|
expect(row).to be_a Hash
|
394
|
-
expect(row['Date']).to eq Date
|
395
|
-
expect(row['Amount']).to eq
|
412
|
+
expect(row['Date']).to eq first_data_row['Date']
|
413
|
+
expect(row['Amount']).to eq first_data_row['Amount']
|
396
414
|
expect(row['Code']).to be_nil
|
397
415
|
expect(row['Remark']).to be_nil
|
398
416
|
expect(row['dummy']).to be_nil
|
399
417
|
row = rows[13]
|
400
418
|
expect(row).to be_a Hash
|
401
|
-
expect(row['Date']).to eq Date
|
402
|
-
expect(row['Amount']).to eq
|
419
|
+
expect(row['Date']).to eq data_row_13['Date']
|
420
|
+
expect(row['Amount']).to eq data_row_13['Amount']
|
403
421
|
expect(row['Code']).to be_nil
|
404
422
|
expect(row['Remark']).to be_nil
|
405
423
|
expect(row['dummy']).to be_nil
|
@@ -408,11 +426,11 @@ describe 'Libis::Tools::Spreadsheet' do
|
|
408
426
|
end
|
409
427
|
|
410
428
|
context 'well-formed with optional headers' do
|
411
|
-
let(:required_headers) {
|
412
|
-
let(:optional_headers) {
|
429
|
+
let(:required_headers) {%w'Date Amount'}
|
430
|
+
let(:optional_headers) {%w'Code'}
|
413
431
|
|
414
432
|
it 'opens correctly' do
|
415
|
-
expect {
|
433
|
+
expect {ss}.not_to raise_error
|
416
434
|
end
|
417
435
|
|
418
436
|
it 'contains required and optional headers' do
|
@@ -422,15 +440,20 @@ describe 'Libis::Tools::Spreadsheet' do
|
|
422
440
|
optional_headers.each do |header|
|
423
441
|
expect(ss.headers).to include header
|
424
442
|
end
|
425
|
-
expect(ss.headers).to eq
|
443
|
+
expect(ss.headers).to eq required_headers + optional_headers
|
444
|
+
end
|
445
|
+
|
446
|
+
it 'each returns header and data rows' do
|
447
|
+
expect(ss.each.count).to eq size_with_headers
|
448
|
+
expect(ss.each.first.keys).to eq required_headers + optional_headers
|
426
449
|
end
|
427
450
|
|
428
451
|
it '#shift returns Hash object' do
|
429
452
|
row = ss.shift
|
430
453
|
expect(row).to be_a Hash
|
431
|
-
expect(row['Date']).to eq Date
|
432
|
-
expect(row['Amount']).to eq
|
433
|
-
expect(row['Code']).to eq
|
454
|
+
expect(row['Date']).to eq first_data_row['Date']
|
455
|
+
expect(row['Amount']).to eq first_data_row['Amount']
|
456
|
+
expect(row['Code']).to eq first_data_row['Code']
|
434
457
|
expect(row['Remark']).to be_nil
|
435
458
|
expect(row['dummy']).to be_nil
|
436
459
|
end
|
@@ -438,19 +461,19 @@ describe 'Libis::Tools::Spreadsheet' do
|
|
438
461
|
it '#parse returns Array of Hash objects' do
|
439
462
|
rows = ss.parse
|
440
463
|
expect(rows).to be_a Array
|
441
|
-
expect(rows.size).to eq
|
464
|
+
expect(rows.size).to eq size_without_headers
|
442
465
|
row = rows[0]
|
443
466
|
expect(row).to be_a Hash
|
444
|
-
expect(row['Date']).to eq Date
|
445
|
-
expect(row['Amount']).to eq
|
446
|
-
expect(row['Code']).to eq
|
467
|
+
expect(row['Date']).to eq first_data_row['Date']
|
468
|
+
expect(row['Amount']).to eq first_data_row['Amount']
|
469
|
+
expect(row['Code']).to eq first_data_row['Code']
|
447
470
|
expect(row['Remark']).to be_nil
|
448
471
|
expect(row['dummy']).to be_nil
|
449
472
|
row = rows[13]
|
450
473
|
expect(row).to be_a Hash
|
451
|
-
expect(row['Date']).to eq Date
|
452
|
-
expect(row['Amount']).to eq
|
453
|
-
expect(row['Code']).to eq
|
474
|
+
expect(row['Date']).to eq data_row_13['Date']
|
475
|
+
expect(row['Amount']).to eq data_row_13['Amount']
|
476
|
+
expect(row['Code']).to eq data_row_13['Code']
|
454
477
|
expect(row['Remark']).to be_nil
|
455
478
|
expect(row['dummy']).to be_nil
|
456
479
|
end
|
@@ -459,11 +482,11 @@ describe 'Libis::Tools::Spreadsheet' do
|
|
459
482
|
|
460
483
|
context 'missing optional headers' do
|
461
484
|
|
462
|
-
let(:required_headers) {
|
463
|
-
let(:optional_headers) {
|
485
|
+
let(:required_headers) {%w'Date Amount Code Remark'}
|
486
|
+
let(:optional_headers) {%w'dummy'}
|
464
487
|
|
465
488
|
it 'opens correctly' do
|
466
|
-
expect {
|
489
|
+
expect {ss}.not_to raise_error
|
467
490
|
end
|
468
491
|
|
469
492
|
it 'contains only required headers' do
|
@@ -473,46 +496,51 @@ describe 'Libis::Tools::Spreadsheet' do
|
|
473
496
|
optional_headers.each do |header|
|
474
497
|
expect(ss.headers).not_to include header
|
475
498
|
end
|
476
|
-
expect(ss.headers).to eq
|
499
|
+
expect(ss.headers).to eq required_headers
|
500
|
+
end
|
501
|
+
|
502
|
+
it 'each returns header and data rows' do
|
503
|
+
expect(ss.each.count).to eq size_with_headers
|
504
|
+
expect(ss.each.first.keys).to eq required_headers
|
477
505
|
end
|
478
506
|
|
479
507
|
it '#shift returns Hash object' do
|
480
508
|
row = ss.shift
|
481
509
|
expect(row).to be_a Hash
|
482
|
-
expect(row['Date']).to eq Date
|
483
|
-
expect(row['Amount']).to eq
|
484
|
-
expect(row['Code']).to eq
|
485
|
-
expect(row['Remark']).to eq '
|
510
|
+
expect(row['Date']).to eq first_data_row['Date']
|
511
|
+
expect(row['Amount']).to eq first_data_row['Amount']
|
512
|
+
expect(row['Code']).to eq first_data_row['Code']
|
513
|
+
expect(row['Remark']).to eq first_data_row['Remark']
|
486
514
|
expect(row['dummy']).to be_nil
|
487
515
|
end
|
488
516
|
|
489
517
|
it '#parse returns Array of Hash objects' do
|
490
518
|
rows = ss.parse
|
491
519
|
expect(rows).to be_a Array
|
492
|
-
expect(rows.size).to eq
|
520
|
+
expect(rows.size).to eq size_without_headers
|
493
521
|
row = rows[0]
|
494
522
|
expect(row).to be_a Hash
|
495
|
-
expect(row['Date']).to eq Date
|
496
|
-
expect(row['Amount']).to eq
|
497
|
-
expect(row['Code']).to eq
|
498
|
-
expect(row['Remark']).to eq '
|
523
|
+
expect(row['Date']).to eq first_data_row['Date']
|
524
|
+
expect(row['Amount']).to eq first_data_row['Amount']
|
525
|
+
expect(row['Code']).to eq first_data_row['Code']
|
526
|
+
expect(row['Remark']).to eq first_data_row['Remark']
|
499
527
|
expect(row['dummy']).to be_nil
|
500
528
|
row = rows[13]
|
501
529
|
expect(row).to be_a Hash
|
502
|
-
expect(row['Date']).to eq Date
|
503
|
-
expect(row['Amount']).to eq
|
504
|
-
expect(row['Code']).to eq
|
505
|
-
expect(row['Remark']).to eq '
|
530
|
+
expect(row['Date']).to eq data_row_13['Date']
|
531
|
+
expect(row['Amount']).to eq data_row_13['Amount']
|
532
|
+
expect(row['Code']).to eq data_row_13['Code']
|
533
|
+
expect(row['Remark']).to eq data_row_13['Remark']
|
506
534
|
expect(row['dummy']).to be_nil
|
507
535
|
end
|
508
536
|
|
509
537
|
end
|
510
538
|
|
511
539
|
context 'missing required header' do
|
512
|
-
let(:required_headers) {
|
540
|
+
let(:required_headers) {%w'Date Amount Code Remark dummy'}
|
513
541
|
|
514
542
|
it 'throws error when opened' do
|
515
|
-
expect {
|
543
|
+
expect {ss}.to raise_error(RuntimeError, 'Sheet does not contain enough columns.')
|
516
544
|
end
|
517
545
|
|
518
546
|
end
|
@@ -520,50 +548,55 @@ describe 'Libis::Tools::Spreadsheet' do
|
|
520
548
|
end
|
521
549
|
|
522
550
|
context 'blank rows with headers' do
|
523
|
-
let(:file_name) {
|
551
|
+
let(:file_name) {'test.xlsx|ExpensesBlankRows'}
|
524
552
|
|
525
553
|
context 'well-formed' do
|
526
554
|
|
527
|
-
let(:required_headers) {
|
555
|
+
let(:required_headers) {%w'Date Amount'}
|
528
556
|
|
529
557
|
it 'opens correctly' do
|
530
|
-
expect{
|
558
|
+
expect {ss}.not_to raise_error
|
531
559
|
end
|
532
560
|
|
533
561
|
it 'contains expected headers' do
|
534
562
|
required_headers.each do |header|
|
535
563
|
expect(ss.headers).to include header
|
536
564
|
end
|
537
|
-
expect(ss.headers).to eq
|
565
|
+
expect(ss.headers).to eq real_headers
|
566
|
+
end
|
567
|
+
|
568
|
+
it 'each returns header and data rows' do
|
569
|
+
expect(ss.each.count).to eq size_with_headers
|
570
|
+
expect(ss.each.first).to eq header_row
|
538
571
|
end
|
539
572
|
|
540
573
|
it '#shift returns Hash object' do
|
541
574
|
row = ss.shift
|
542
575
|
expect(row).to be_a Hash
|
543
|
-
expect(row['Date']).to eq Date
|
544
|
-
expect(row['Amount']).to eq
|
545
|
-
expect(row['Code']).to eq
|
546
|
-
expect(row['Remark']).to eq '
|
576
|
+
expect(row['Date']).to eq first_data_row['Date']
|
577
|
+
expect(row['Amount']).to eq first_data_row['Amount']
|
578
|
+
expect(row['Code']).to eq first_data_row['Code']
|
579
|
+
expect(row['Remark']).to eq first_data_row['Remark']
|
547
580
|
expect(row['dummy']).to be_nil
|
548
581
|
end
|
549
582
|
|
550
583
|
it '#parse returns Array of Hash objects' do
|
551
584
|
rows = ss.parse
|
552
585
|
expect(rows).to be_a Array
|
553
|
-
expect(rows.size).to eq
|
586
|
+
expect(rows.size).to eq size_without_headers
|
554
587
|
row = rows[0]
|
555
588
|
expect(row).to be_a Hash
|
556
|
-
expect(row['Date']).to eq Date
|
557
|
-
expect(row['Amount']).to eq
|
558
|
-
expect(row['Code']).to eq
|
559
|
-
expect(row['Remark']).to eq '
|
589
|
+
expect(row['Date']).to eq first_data_row['Date']
|
590
|
+
expect(row['Amount']).to eq first_data_row['Amount']
|
591
|
+
expect(row['Code']).to eq first_data_row['Code']
|
592
|
+
expect(row['Remark']).to eq first_data_row['Remark']
|
560
593
|
expect(row['dummy']).to be_nil
|
561
594
|
row = rows[13]
|
562
595
|
expect(row).to be_a Hash
|
563
|
-
expect(row['Date']).to eq Date
|
564
|
-
expect(row['Amount']).to eq
|
565
|
-
expect(row['Code']).to eq
|
566
|
-
expect(row['Remark']).to eq '
|
596
|
+
expect(row['Date']).to eq data_row_13['Date']
|
597
|
+
expect(row['Amount']).to eq data_row_13['Amount']
|
598
|
+
expect(row['Code']).to eq data_row_13['Code']
|
599
|
+
expect(row['Remark']).to eq data_row_13['Remark']
|
567
600
|
expect(row['dummy']).to be_nil
|
568
601
|
end
|
569
602
|
|
@@ -571,46 +604,51 @@ describe 'Libis::Tools::Spreadsheet' do
|
|
571
604
|
|
572
605
|
context 'not specified' do
|
573
606
|
|
574
|
-
let(:required_headers) {
|
607
|
+
let(:required_headers) {[]}
|
575
608
|
|
576
609
|
it 'opens correctly' do
|
577
|
-
expect{
|
610
|
+
expect {ss}.not_to raise_error
|
578
611
|
end
|
579
612
|
|
580
613
|
it 'contains expected headers' do
|
581
614
|
required_headers.each do |header|
|
582
615
|
expect(ss.headers).to include header
|
583
616
|
end
|
584
|
-
expect(ss.headers).to eq
|
617
|
+
expect(ss.headers).to eq real_headers
|
618
|
+
end
|
619
|
+
|
620
|
+
it 'each returns header and data rows' do
|
621
|
+
expect(ss.each.count).to eq size_with_headers
|
622
|
+
expect(ss.each.first).to eq header_row
|
585
623
|
end
|
586
624
|
|
587
625
|
it '#shift returns Hash object' do
|
588
626
|
row = ss.shift
|
589
627
|
expect(row).to be_a Hash
|
590
|
-
expect(row['Date']).to eq Date
|
591
|
-
expect(row['Amount']).to eq
|
592
|
-
expect(row['Code']).to eq
|
593
|
-
expect(row['Remark']).to eq '
|
628
|
+
expect(row['Date']).to eq first_data_row['Date']
|
629
|
+
expect(row['Amount']).to eq first_data_row['Amount']
|
630
|
+
expect(row['Code']).to eq first_data_row['Code']
|
631
|
+
expect(row['Remark']).to eq first_data_row['Remark']
|
594
632
|
expect(row['dummy']).to be_nil
|
595
633
|
end
|
596
634
|
|
597
635
|
it '#parse returns Array of Hash objects' do
|
598
636
|
rows = ss.parse
|
599
637
|
expect(rows).to be_a Array
|
600
|
-
expect(rows.size).to eq
|
638
|
+
expect(rows.size).to eq size_without_headers
|
601
639
|
row = rows[0]
|
602
640
|
expect(row).to be_a Hash
|
603
|
-
expect(row['Date']).to eq Date
|
604
|
-
expect(row['Amount']).to eq
|
605
|
-
expect(row['Code']).to eq
|
606
|
-
expect(row['Remark']).to eq '
|
641
|
+
expect(row['Date']).to eq first_data_row['Date']
|
642
|
+
expect(row['Amount']).to eq first_data_row['Amount']
|
643
|
+
expect(row['Code']).to eq first_data_row['Code']
|
644
|
+
expect(row['Remark']).to eq first_data_row['Remark']
|
607
645
|
expect(row['dummy']).to be_nil
|
608
646
|
row = rows[13]
|
609
647
|
expect(row).to be_a Hash
|
610
|
-
expect(row['Date']).to eq Date
|
611
|
-
expect(row['Amount']).to eq
|
612
|
-
expect(row['Code']).to eq
|
613
|
-
expect(row['Remark']).to eq '
|
648
|
+
expect(row['Date']).to eq data_row_13['Date']
|
649
|
+
expect(row['Amount']).to eq data_row_13['Amount']
|
650
|
+
expect(row['Code']).to eq data_row_13['Code']
|
651
|
+
expect(row['Remark']).to eq data_row_13['Remark']
|
614
652
|
expect(row['dummy']).to be_nil
|
615
653
|
end
|
616
654
|
|
@@ -618,37 +656,42 @@ describe 'Libis::Tools::Spreadsheet' do
|
|
618
656
|
|
619
657
|
context 'not well-formed' do
|
620
658
|
|
621
|
-
let(:required_headers) {
|
659
|
+
let(:required_headers) {%w'Date dummy1 Amount dummy2'}
|
622
660
|
|
623
661
|
it 'throws error when opened' do
|
624
|
-
expect {
|
662
|
+
expect {ss}.to raise_error(RuntimeError, 'Headers not found: ["dummy1", "dummy2"].')
|
625
663
|
end
|
626
664
|
end
|
627
665
|
|
628
666
|
end
|
629
667
|
|
630
668
|
context 'blank rows without headers' do
|
631
|
-
let(:file_name) {
|
669
|
+
let(:file_name) {'test.xlsx|ExpensesBlankRowsNoHeaders'}
|
632
670
|
|
633
671
|
context 'well-formed and strict' do
|
634
|
-
let(:required_headers) {
|
672
|
+
let(:required_headers) {%w'Date Amount'}
|
635
673
|
|
636
674
|
it 'opens correctly' do
|
637
|
-
expect {
|
675
|
+
expect {ss}.not_to raise_error
|
638
676
|
end
|
639
677
|
|
640
678
|
it 'contains only required headers' do
|
641
679
|
required_headers.each do |header|
|
642
680
|
expect(ss.headers).to include header
|
643
681
|
end
|
644
|
-
expect(ss.headers).to eq
|
682
|
+
expect(ss.headers).to eq required_headers
|
683
|
+
end
|
684
|
+
|
685
|
+
it 'each returns header and data rows' do
|
686
|
+
expect(ss.each.count).to eq size_with_headers
|
687
|
+
expect(ss.each.first.keys).to eq required_headers
|
645
688
|
end
|
646
689
|
|
647
690
|
it '#shift returns Hash object' do
|
648
691
|
row = ss.shift
|
649
692
|
expect(row).to be_a Hash
|
650
|
-
expect(row['Date']).to eq Date
|
651
|
-
expect(row['Amount']).to eq
|
693
|
+
expect(row['Date']).to eq first_data_row['Date']
|
694
|
+
expect(row['Amount']).to eq first_data_row['Amount']
|
652
695
|
expect(row['Code']).to be_nil
|
653
696
|
expect(row['Remark']).to be_nil
|
654
697
|
expect(row['dummy']).to be_nil
|
@@ -657,18 +700,18 @@ describe 'Libis::Tools::Spreadsheet' do
|
|
657
700
|
it '#parse returns Array of Hash objects' do
|
658
701
|
rows = ss.parse
|
659
702
|
expect(rows).to be_a Array
|
660
|
-
expect(rows.size).to eq
|
703
|
+
expect(rows.size).to eq size_without_headers
|
661
704
|
row = rows[0]
|
662
705
|
expect(row).to be_a Hash
|
663
|
-
expect(row['Date']).to eq Date
|
664
|
-
expect(row['Amount']).to eq
|
706
|
+
expect(row['Date']).to eq first_data_row['Date']
|
707
|
+
expect(row['Amount']).to eq first_data_row['Amount']
|
665
708
|
expect(row['Code']).to be_nil
|
666
709
|
expect(row['Remark']).to be_nil
|
667
710
|
expect(row['dummy']).to be_nil
|
668
711
|
row = rows[13]
|
669
712
|
expect(row).to be_a Hash
|
670
|
-
expect(row['Date']).to eq Date
|
671
|
-
expect(row['Amount']).to eq
|
713
|
+
expect(row['Date']).to eq data_row_13['Date']
|
714
|
+
expect(row['Amount']).to eq data_row_13['Amount']
|
672
715
|
expect(row['Code']).to be_nil
|
673
716
|
expect(row['Remark']).to be_nil
|
674
717
|
expect(row['dummy']).to be_nil
|
@@ -677,11 +720,11 @@ describe 'Libis::Tools::Spreadsheet' do
|
|
677
720
|
end
|
678
721
|
|
679
722
|
context 'well-formed with optional headers' do
|
680
|
-
let(:required_headers) {
|
681
|
-
let(:optional_headers) {
|
723
|
+
let(:required_headers) {%w'Date Amount'}
|
724
|
+
let(:optional_headers) {%w'Code'}
|
682
725
|
|
683
726
|
it 'opens correctly' do
|
684
|
-
expect {
|
727
|
+
expect {ss}.not_to raise_error
|
685
728
|
end
|
686
729
|
|
687
730
|
it 'contains required and optional headers' do
|
@@ -691,15 +734,20 @@ describe 'Libis::Tools::Spreadsheet' do
|
|
691
734
|
optional_headers.each do |header|
|
692
735
|
expect(ss.headers).to include header
|
693
736
|
end
|
694
|
-
expect(ss.headers).to eq
|
737
|
+
expect(ss.headers).to eq required_headers + optional_headers
|
738
|
+
end
|
739
|
+
|
740
|
+
it 'each returns header and data rows' do
|
741
|
+
expect(ss.each.count).to eq size_with_headers
|
742
|
+
expect(ss.each.first.keys).to eq required_headers + optional_headers
|
695
743
|
end
|
696
744
|
|
697
745
|
it '#shift returns Hash object' do
|
698
746
|
row = ss.shift
|
699
747
|
expect(row).to be_a Hash
|
700
|
-
expect(row['Date']).to eq Date
|
701
|
-
expect(row['Amount']).to eq
|
702
|
-
expect(row['Code']).to eq
|
748
|
+
expect(row['Date']).to eq first_data_row['Date']
|
749
|
+
expect(row['Amount']).to eq first_data_row['Amount']
|
750
|
+
expect(row['Code']).to eq first_data_row['Code']
|
703
751
|
expect(row['Remark']).to be_nil
|
704
752
|
expect(row['dummy']).to be_nil
|
705
753
|
end
|
@@ -707,19 +755,19 @@ describe 'Libis::Tools::Spreadsheet' do
|
|
707
755
|
it '#parse returns Array of Hash objects' do
|
708
756
|
rows = ss.parse
|
709
757
|
expect(rows).to be_a Array
|
710
|
-
expect(rows.size).to eq
|
758
|
+
expect(rows.size).to eq size_without_headers
|
711
759
|
row = rows[0]
|
712
760
|
expect(row).to be_a Hash
|
713
|
-
expect(row['Date']).to eq Date
|
714
|
-
expect(row['Amount']).to eq
|
715
|
-
expect(row['Code']).to eq
|
761
|
+
expect(row['Date']).to eq first_data_row['Date']
|
762
|
+
expect(row['Amount']).to eq first_data_row['Amount']
|
763
|
+
expect(row['Code']).to eq first_data_row['Code']
|
716
764
|
expect(row['Remark']).to be_nil
|
717
765
|
expect(row['dummy']).to be_nil
|
718
766
|
row = rows[13]
|
719
767
|
expect(row).to be_a Hash
|
720
|
-
expect(row['Date']).to eq Date
|
721
|
-
expect(row['Amount']).to eq
|
722
|
-
expect(row['Code']).to eq
|
768
|
+
expect(row['Date']).to eq data_row_13['Date']
|
769
|
+
expect(row['Amount']).to eq data_row_13['Amount']
|
770
|
+
expect(row['Code']).to eq data_row_13['Code']
|
723
771
|
expect(row['Remark']).to be_nil
|
724
772
|
expect(row['dummy']).to be_nil
|
725
773
|
end
|
@@ -728,11 +776,11 @@ describe 'Libis::Tools::Spreadsheet' do
|
|
728
776
|
|
729
777
|
context 'missing optional headers' do
|
730
778
|
|
731
|
-
let(:required_headers) {
|
732
|
-
let(:optional_headers) {
|
779
|
+
let(:required_headers) {%w'Date Amount Code Remark'}
|
780
|
+
let(:optional_headers) {%w'dummy'}
|
733
781
|
|
734
782
|
it 'opens correctly' do
|
735
|
-
expect {
|
783
|
+
expect {ss}.not_to raise_error
|
736
784
|
end
|
737
785
|
|
738
786
|
it 'contains only required headers' do
|
@@ -742,46 +790,51 @@ describe 'Libis::Tools::Spreadsheet' do
|
|
742
790
|
optional_headers.each do |header|
|
743
791
|
expect(ss.headers).not_to include header
|
744
792
|
end
|
745
|
-
expect(ss.headers).to eq
|
793
|
+
expect(ss.headers).to eq required_headers
|
794
|
+
end
|
795
|
+
|
796
|
+
it 'each returns header and data rows' do
|
797
|
+
expect(ss.each.count).to eq size_with_headers
|
798
|
+
expect(ss.each.first.keys).to eq required_headers
|
746
799
|
end
|
747
800
|
|
748
801
|
it '#shift returns Hash object' do
|
749
802
|
row = ss.shift
|
750
803
|
expect(row).to be_a Hash
|
751
|
-
expect(row['Date']).to eq Date
|
752
|
-
expect(row['Amount']).to eq
|
753
|
-
expect(row['Code']).to eq
|
754
|
-
expect(row['Remark']).to eq '
|
804
|
+
expect(row['Date']).to eq first_data_row['Date']
|
805
|
+
expect(row['Amount']).to eq first_data_row['Amount']
|
806
|
+
expect(row['Code']).to eq first_data_row['Code']
|
807
|
+
expect(row['Remark']).to eq first_data_row['Remark']
|
755
808
|
expect(row['dummy']).to be_nil
|
756
809
|
end
|
757
810
|
|
758
811
|
it '#parse returns Array of Hash objects' do
|
759
812
|
rows = ss.parse
|
760
813
|
expect(rows).to be_a Array
|
761
|
-
expect(rows.size).to eq
|
814
|
+
expect(rows.size).to eq size_without_headers
|
762
815
|
row = rows[0]
|
763
816
|
expect(row).to be_a Hash
|
764
|
-
expect(row['Date']).to eq Date
|
765
|
-
expect(row['Amount']).to eq
|
766
|
-
expect(row['Code']).to eq
|
767
|
-
expect(row['Remark']).to eq '
|
817
|
+
expect(row['Date']).to eq first_data_row['Date']
|
818
|
+
expect(row['Amount']).to eq first_data_row['Amount']
|
819
|
+
expect(row['Code']).to eq first_data_row['Code']
|
820
|
+
expect(row['Remark']).to eq first_data_row['Remark']
|
768
821
|
expect(row['dummy']).to be_nil
|
769
822
|
row = rows[13]
|
770
823
|
expect(row).to be_a Hash
|
771
|
-
expect(row['Date']).to eq Date
|
772
|
-
expect(row['Amount']).to eq
|
773
|
-
expect(row['Code']).to eq
|
774
|
-
expect(row['Remark']).to eq '
|
824
|
+
expect(row['Date']).to eq data_row_13['Date']
|
825
|
+
expect(row['Amount']).to eq data_row_13['Amount']
|
826
|
+
expect(row['Code']).to eq data_row_13['Code']
|
827
|
+
expect(row['Remark']).to eq data_row_13['Remark']
|
775
828
|
expect(row['dummy']).to be_nil
|
776
829
|
end
|
777
830
|
|
778
831
|
end
|
779
832
|
|
780
833
|
context 'missing required header' do
|
781
|
-
let(:required_headers) {
|
834
|
+
let(:required_headers) {%w'Date Amount Code Remark dummy'}
|
782
835
|
|
783
836
|
it 'throws error when opened' do
|
784
|
-
expect {
|
837
|
+
expect {ss}.to raise_error(RuntimeError, 'Sheet does not contain enough columns.')
|
785
838
|
end
|
786
839
|
|
787
840
|
end
|
@@ -789,50 +842,55 @@ describe 'Libis::Tools::Spreadsheet' do
|
|
789
842
|
end
|
790
843
|
|
791
844
|
context 'blank columns with headers' do
|
792
|
-
let(:file_name) {
|
845
|
+
let(:file_name) {'test.xlsx|ExpensesBlankColumns'}
|
793
846
|
|
794
847
|
context 'well-formed' do
|
795
848
|
|
796
|
-
let(:required_headers) {
|
849
|
+
let(:required_headers) {%w'Date Amount'}
|
797
850
|
|
798
851
|
it 'opens correctly' do
|
799
|
-
expect{
|
852
|
+
expect {ss}.not_to raise_error
|
800
853
|
end
|
801
854
|
|
802
855
|
it 'contains expected headers' do
|
803
856
|
required_headers.each do |header|
|
804
857
|
expect(ss.headers).to include header
|
805
858
|
end
|
806
|
-
expect(ss.headers).to eq
|
859
|
+
expect(ss.headers).to eq real_headers
|
860
|
+
end
|
861
|
+
|
862
|
+
it 'each returns header and data rows' do
|
863
|
+
expect(ss.each.count).to eq size_with_headers
|
864
|
+
expect(ss.each.first).to eq header_row
|
807
865
|
end
|
808
866
|
|
809
867
|
it '#shift returns Hash object' do
|
810
868
|
row = ss.shift
|
811
869
|
expect(row).to be_a Hash
|
812
|
-
expect(row['Date']).to eq Date
|
813
|
-
expect(row['Amount']).to eq
|
814
|
-
expect(row['Code']).to eq
|
815
|
-
expect(row['Remark']).to eq '
|
870
|
+
expect(row['Date']).to eq first_data_row['Date']
|
871
|
+
expect(row['Amount']).to eq first_data_row['Amount']
|
872
|
+
expect(row['Code']).to eq first_data_row['Code']
|
873
|
+
expect(row['Remark']).to eq first_data_row['Remark']
|
816
874
|
expect(row['dummy']).to be_nil
|
817
875
|
end
|
818
876
|
|
819
877
|
it '#parse returns Array of Hash objects' do
|
820
878
|
rows = ss.parse
|
821
879
|
expect(rows).to be_a Array
|
822
|
-
expect(rows.size).to eq
|
880
|
+
expect(rows.size).to eq size_without_headers
|
823
881
|
row = rows[0]
|
824
882
|
expect(row).to be_a Hash
|
825
|
-
expect(row['Date']).to eq Date
|
826
|
-
expect(row['Amount']).to eq
|
827
|
-
expect(row['Code']).to eq
|
828
|
-
expect(row['Remark']).to eq '
|
883
|
+
expect(row['Date']).to eq first_data_row['Date']
|
884
|
+
expect(row['Amount']).to eq first_data_row['Amount']
|
885
|
+
expect(row['Code']).to eq first_data_row['Code']
|
886
|
+
expect(row['Remark']).to eq first_data_row['Remark']
|
829
887
|
expect(row['dummy']).to be_nil
|
830
888
|
row = rows[13]
|
831
889
|
expect(row).to be_a Hash
|
832
|
-
expect(row['Date']).to eq Date
|
833
|
-
expect(row['Amount']).to eq
|
834
|
-
expect(row['Code']).to eq
|
835
|
-
expect(row['Remark']).to eq '
|
890
|
+
expect(row['Date']).to eq data_row_13['Date']
|
891
|
+
expect(row['Amount']).to eq data_row_13['Amount']
|
892
|
+
expect(row['Code']).to eq data_row_13['Code']
|
893
|
+
expect(row['Remark']).to eq data_row_13['Remark']
|
836
894
|
expect(row['dummy']).to be_nil
|
837
895
|
end
|
838
896
|
|
@@ -840,46 +898,51 @@ describe 'Libis::Tools::Spreadsheet' do
|
|
840
898
|
|
841
899
|
context 'not specified' do
|
842
900
|
|
843
|
-
let(:required_headers) {
|
901
|
+
let(:required_headers) {[]}
|
844
902
|
|
845
903
|
it 'opens correctly' do
|
846
|
-
expect{
|
904
|
+
expect {ss}.not_to raise_error
|
847
905
|
end
|
848
906
|
|
849
907
|
it 'contains expected headers' do
|
850
908
|
required_headers.each do |header|
|
851
909
|
expect(ss.headers).to include header
|
852
910
|
end
|
853
|
-
expect(ss.headers).to eq
|
911
|
+
expect(ss.headers).to eq real_headers
|
912
|
+
end
|
913
|
+
|
914
|
+
it 'each returns header and data rows' do
|
915
|
+
expect(ss.each.count).to eq size_with_headers
|
916
|
+
expect(ss.each.first).to eq header_row
|
854
917
|
end
|
855
918
|
|
856
919
|
it '#shift returns Hash object' do
|
857
920
|
row = ss.shift
|
858
921
|
expect(row).to be_a Hash
|
859
|
-
expect(row['Date']).to eq Date
|
860
|
-
expect(row['Amount']).to eq
|
861
|
-
expect(row['Code']).to eq
|
862
|
-
expect(row['Remark']).to eq '
|
922
|
+
expect(row['Date']).to eq first_data_row['Date']
|
923
|
+
expect(row['Amount']).to eq first_data_row['Amount']
|
924
|
+
expect(row['Code']).to eq first_data_row['Code']
|
925
|
+
expect(row['Remark']).to eq first_data_row['Remark']
|
863
926
|
expect(row['dummy']).to be_nil
|
864
927
|
end
|
865
928
|
|
866
929
|
it '#parse returns Array of Hash objects' do
|
867
930
|
rows = ss.parse
|
868
931
|
expect(rows).to be_a Array
|
869
|
-
expect(rows.size).to eq
|
932
|
+
expect(rows.size).to eq size_without_headers
|
870
933
|
row = rows[0]
|
871
934
|
expect(row).to be_a Hash
|
872
|
-
expect(row['Date']).to eq Date
|
873
|
-
expect(row['Amount']).to eq
|
874
|
-
expect(row['Code']).to eq
|
875
|
-
expect(row['Remark']).to eq '
|
935
|
+
expect(row['Date']).to eq first_data_row['Date']
|
936
|
+
expect(row['Amount']).to eq first_data_row['Amount']
|
937
|
+
expect(row['Code']).to eq first_data_row['Code']
|
938
|
+
expect(row['Remark']).to eq first_data_row['Remark']
|
876
939
|
expect(row['dummy']).to be_nil
|
877
940
|
row = rows[13]
|
878
941
|
expect(row).to be_a Hash
|
879
|
-
expect(row['Date']).to eq Date
|
880
|
-
expect(row['Amount']).to eq
|
881
|
-
expect(row['Code']).to eq
|
882
|
-
expect(row['Remark']).to eq '
|
942
|
+
expect(row['Date']).to eq data_row_13['Date']
|
943
|
+
expect(row['Amount']).to eq data_row_13['Amount']
|
944
|
+
expect(row['Code']).to eq data_row_13['Code']
|
945
|
+
expect(row['Remark']).to eq data_row_13['Remark']
|
883
946
|
expect(row['dummy']).to be_nil
|
884
947
|
end
|
885
948
|
|
@@ -887,37 +950,42 @@ describe 'Libis::Tools::Spreadsheet' do
|
|
887
950
|
|
888
951
|
context 'not well-formed' do
|
889
952
|
|
890
|
-
let(:required_headers) {
|
953
|
+
let(:required_headers) {%w'Date dummy1 Amount dummy2'}
|
891
954
|
|
892
955
|
it 'throws error when opened' do
|
893
|
-
expect {
|
956
|
+
expect {ss}.to raise_error(RuntimeError, 'Headers not found: ["dummy1", "dummy2"].')
|
894
957
|
end
|
895
958
|
end
|
896
959
|
|
897
960
|
end
|
898
961
|
|
899
962
|
context 'blank columns without headers' do
|
900
|
-
let(:file_name) {
|
963
|
+
let(:file_name) {'test.xlsx|ExpensesBlankColumnsNoHeaders'}
|
901
964
|
|
902
965
|
context 'well-formed and strict' do
|
903
|
-
let(:required_headers) {
|
966
|
+
let(:required_headers) {%w'Date Amount'}
|
904
967
|
|
905
968
|
it 'opens correctly' do
|
906
|
-
expect {
|
969
|
+
expect {ss}.not_to raise_error
|
907
970
|
end
|
908
971
|
|
909
972
|
it 'contains only required headers' do
|
910
973
|
required_headers.each do |header|
|
911
974
|
expect(ss.headers).to include header
|
912
975
|
end
|
913
|
-
expect(ss.headers).to eq
|
976
|
+
expect(ss.headers).to eq required_headers
|
977
|
+
end
|
978
|
+
|
979
|
+
it 'each returns header and data rows' do
|
980
|
+
expect(ss.each.count).to eq size_with_headers
|
981
|
+
expect(ss.each.first.keys).to eq required_headers
|
914
982
|
end
|
915
983
|
|
916
984
|
it '#shift returns Hash object' do
|
917
985
|
row = ss.shift
|
918
986
|
expect(row).to be_a Hash
|
919
|
-
expect(row['Date']).to eq Date
|
920
|
-
expect(row['Amount']).to eq
|
987
|
+
expect(row['Date']).to eq first_data_row['Date']
|
988
|
+
expect(row['Amount']).to eq first_data_row['Amount']
|
921
989
|
expect(row['Code']).to be_nil
|
922
990
|
expect(row['Remark']).to be_nil
|
923
991
|
expect(row['dummy']).to be_nil
|
@@ -926,18 +994,18 @@ describe 'Libis::Tools::Spreadsheet' do
|
|
926
994
|
it '#parse returns Array of Hash objects' do
|
927
995
|
rows = ss.parse
|
928
996
|
expect(rows).to be_a Array
|
929
|
-
expect(rows.size).to eq
|
997
|
+
expect(rows.size).to eq size_without_headers
|
930
998
|
row = rows[0]
|
931
999
|
expect(row).to be_a Hash
|
932
|
-
expect(row['Date']).to eq Date
|
933
|
-
expect(row['Amount']).to eq
|
1000
|
+
expect(row['Date']).to eq first_data_row['Date']
|
1001
|
+
expect(row['Amount']).to eq first_data_row['Amount']
|
934
1002
|
expect(row['Code']).to be_nil
|
935
1003
|
expect(row['Remark']).to be_nil
|
936
1004
|
expect(row['dummy']).to be_nil
|
937
1005
|
row = rows[13]
|
938
1006
|
expect(row).to be_a Hash
|
939
|
-
expect(row['Date']).to eq Date
|
940
|
-
expect(row['Amount']).to eq
|
1007
|
+
expect(row['Date']).to eq data_row_13['Date']
|
1008
|
+
expect(row['Amount']).to eq data_row_13['Amount']
|
941
1009
|
expect(row['Code']).to be_nil
|
942
1010
|
expect(row['Remark']).to be_nil
|
943
1011
|
expect(row['dummy']).to be_nil
|
@@ -946,11 +1014,11 @@ describe 'Libis::Tools::Spreadsheet' do
|
|
946
1014
|
end
|
947
1015
|
|
948
1016
|
context 'well-formed with optional headers' do
|
949
|
-
let(:required_headers) {
|
950
|
-
let(:optional_headers) {
|
1017
|
+
let(:required_headers) {%w'Date Amount'}
|
1018
|
+
let(:optional_headers) {%w'Code'}
|
951
1019
|
|
952
1020
|
it 'opens correctly' do
|
953
|
-
expect {
|
1021
|
+
expect {ss}.not_to raise_error
|
954
1022
|
end
|
955
1023
|
|
956
1024
|
it 'contains required and optional headers' do
|
@@ -960,15 +1028,20 @@ describe 'Libis::Tools::Spreadsheet' do
|
|
960
1028
|
optional_headers.each do |header|
|
961
1029
|
expect(ss.headers).to include header
|
962
1030
|
end
|
963
|
-
expect(ss.headers).to eq
|
1031
|
+
expect(ss.headers).to eq required_headers + optional_headers
|
1032
|
+
end
|
1033
|
+
|
1034
|
+
it 'each returns header and data rows' do
|
1035
|
+
expect(ss.each.count).to eq size_with_headers
|
1036
|
+
expect(ss.each.first.keys).to eq required_headers + optional_headers
|
964
1037
|
end
|
965
1038
|
|
966
1039
|
it '#shift returns Hash object' do
|
967
1040
|
row = ss.shift
|
968
1041
|
expect(row).to be_a Hash
|
969
|
-
expect(row['Date']).to eq Date
|
970
|
-
expect(row['Amount']).to eq
|
971
|
-
expect(row['Code']).to eq
|
1042
|
+
expect(row['Date']).to eq first_data_row['Date']
|
1043
|
+
expect(row['Amount']).to eq first_data_row['Amount']
|
1044
|
+
expect(row['Code']).to eq first_data_row['Code']
|
972
1045
|
expect(row['Remark']).to be_nil
|
973
1046
|
expect(row['dummy']).to be_nil
|
974
1047
|
end
|
@@ -976,19 +1049,19 @@ describe 'Libis::Tools::Spreadsheet' do
|
|
976
1049
|
it '#parse returns Array of Hash objects' do
|
977
1050
|
rows = ss.parse
|
978
1051
|
expect(rows).to be_a Array
|
979
|
-
expect(rows.size).to eq
|
1052
|
+
expect(rows.size).to eq size_without_headers
|
980
1053
|
row = rows[0]
|
981
1054
|
expect(row).to be_a Hash
|
982
|
-
expect(row['Date']).to eq Date
|
983
|
-
expect(row['Amount']).to eq
|
984
|
-
expect(row['Code']).to eq
|
1055
|
+
expect(row['Date']).to eq first_data_row['Date']
|
1056
|
+
expect(row['Amount']).to eq first_data_row['Amount']
|
1057
|
+
expect(row['Code']).to eq first_data_row['Code']
|
985
1058
|
expect(row['Remark']).to be_nil
|
986
1059
|
expect(row['dummy']).to be_nil
|
987
1060
|
row = rows[13]
|
988
1061
|
expect(row).to be_a Hash
|
989
|
-
expect(row['Date']).to eq Date
|
990
|
-
expect(row['Amount']).to eq
|
991
|
-
expect(row['Code']).to eq
|
1062
|
+
expect(row['Date']).to eq data_row_13['Date']
|
1063
|
+
expect(row['Amount']).to eq data_row_13['Amount']
|
1064
|
+
expect(row['Code']).to eq data_row_13['Code']
|
992
1065
|
expect(row['Remark']).to be_nil
|
993
1066
|
expect(row['dummy']).to be_nil
|
994
1067
|
end
|
@@ -997,11 +1070,11 @@ describe 'Libis::Tools::Spreadsheet' do
|
|
997
1070
|
|
998
1071
|
context 'missing optional headers' do
|
999
1072
|
|
1000
|
-
let(:required_headers) {
|
1001
|
-
let(:optional_headers) {
|
1073
|
+
let(:required_headers) {%w'Date Amount Code Remark'}
|
1074
|
+
let(:optional_headers) {%w'dummy'}
|
1002
1075
|
|
1003
1076
|
it 'opens correctly' do
|
1004
|
-
expect {
|
1077
|
+
expect {ss}.not_to raise_error
|
1005
1078
|
end
|
1006
1079
|
|
1007
1080
|
it 'contains only required headers' do
|
@@ -1011,46 +1084,51 @@ describe 'Libis::Tools::Spreadsheet' do
|
|
1011
1084
|
optional_headers.each do |header|
|
1012
1085
|
expect(ss.headers).not_to include header
|
1013
1086
|
end
|
1014
|
-
expect(ss.headers).to eq
|
1087
|
+
expect(ss.headers).to eq required_headers
|
1088
|
+
end
|
1089
|
+
|
1090
|
+
it 'each returns header and data rows' do
|
1091
|
+
expect(ss.each.count).to eq size_with_headers
|
1092
|
+
expect(ss.each.first.keys).to eq required_headers
|
1015
1093
|
end
|
1016
1094
|
|
1017
1095
|
it '#shift returns Hash object' do
|
1018
1096
|
row = ss.shift
|
1019
1097
|
expect(row).to be_a Hash
|
1020
|
-
expect(row['Date']).to eq Date
|
1021
|
-
expect(row['Amount']).to eq
|
1022
|
-
expect(row['Code']).to eq
|
1023
|
-
expect(row['Remark']).to eq '
|
1098
|
+
expect(row['Date']).to eq first_data_row['Date']
|
1099
|
+
expect(row['Amount']).to eq first_data_row['Amount']
|
1100
|
+
expect(row['Code']).to eq first_data_row['Code']
|
1101
|
+
expect(row['Remark']).to eq first_data_row['Remark']
|
1024
1102
|
expect(row['dummy']).to be_nil
|
1025
1103
|
end
|
1026
1104
|
|
1027
1105
|
it '#parse returns Array of Hash objects' do
|
1028
1106
|
rows = ss.parse
|
1029
1107
|
expect(rows).to be_a Array
|
1030
|
-
expect(rows.size).to eq
|
1108
|
+
expect(rows.size).to eq size_without_headers
|
1031
1109
|
row = rows[0]
|
1032
1110
|
expect(row).to be_a Hash
|
1033
|
-
expect(row['Date']).to eq Date
|
1034
|
-
expect(row['Amount']).to eq
|
1035
|
-
expect(row['Code']).to eq
|
1036
|
-
expect(row['Remark']).to eq '
|
1111
|
+
expect(row['Date']).to eq first_data_row['Date']
|
1112
|
+
expect(row['Amount']).to eq first_data_row['Amount']
|
1113
|
+
expect(row['Code']).to eq first_data_row['Code']
|
1114
|
+
expect(row['Remark']).to eq first_data_row['Remark']
|
1037
1115
|
expect(row['dummy']).to be_nil
|
1038
1116
|
row = rows[13]
|
1039
1117
|
expect(row).to be_a Hash
|
1040
|
-
expect(row['Date']).to eq Date
|
1041
|
-
expect(row['Amount']).to eq
|
1042
|
-
expect(row['Code']).to eq
|
1043
|
-
expect(row['Remark']).to eq '
|
1118
|
+
expect(row['Date']).to eq data_row_13['Date']
|
1119
|
+
expect(row['Amount']).to eq data_row_13['Amount']
|
1120
|
+
expect(row['Code']).to eq data_row_13['Code']
|
1121
|
+
expect(row['Remark']).to eq data_row_13['Remark']
|
1044
1122
|
expect(row['dummy']).to be_nil
|
1045
1123
|
end
|
1046
1124
|
|
1047
1125
|
end
|
1048
1126
|
|
1049
1127
|
context 'missing required header' do
|
1050
|
-
let(:required_headers) {
|
1128
|
+
let(:required_headers) {%w'Date Amount Code Remark dummy'}
|
1051
1129
|
|
1052
1130
|
it 'throws error when opened' do
|
1053
|
-
expect {
|
1131
|
+
expect {ss}.to raise_error(RuntimeError, 'Sheet does not contain enough columns.')
|
1054
1132
|
end
|
1055
1133
|
|
1056
1134
|
end
|
@@ -1058,50 +1136,55 @@ describe 'Libis::Tools::Spreadsheet' do
|
|
1058
1136
|
end
|
1059
1137
|
|
1060
1138
|
context 'blank row and columns with headers' do
|
1061
|
-
let(:file_name) {
|
1139
|
+
let(:file_name) {'test.xlsx|ExpensesBlankRowsAndColumns'}
|
1062
1140
|
|
1063
1141
|
context 'well-formed' do
|
1064
1142
|
|
1065
|
-
let(:required_headers) {
|
1143
|
+
let(:required_headers) {%w'Date Amount'}
|
1066
1144
|
|
1067
1145
|
it 'opens correctly' do
|
1068
|
-
expect{
|
1146
|
+
expect {ss}.not_to raise_error
|
1069
1147
|
end
|
1070
1148
|
|
1071
1149
|
it 'contains expected headers' do
|
1072
1150
|
required_headers.each do |header|
|
1073
1151
|
expect(ss.headers).to include header
|
1074
1152
|
end
|
1075
|
-
expect(ss.headers).to eq
|
1153
|
+
expect(ss.headers).to eq real_headers
|
1154
|
+
end
|
1155
|
+
|
1156
|
+
it 'each returns header and data rows' do
|
1157
|
+
expect(ss.each.count).to eq size_with_headers
|
1158
|
+
expect(ss.each.first).to eq header_row
|
1076
1159
|
end
|
1077
1160
|
|
1078
1161
|
it '#shift returns Hash object' do
|
1079
1162
|
row = ss.shift
|
1080
1163
|
expect(row).to be_a Hash
|
1081
|
-
expect(row['Date']).to eq Date
|
1082
|
-
expect(row['Amount']).to eq
|
1083
|
-
expect(row['Code']).to eq
|
1084
|
-
expect(row['Remark']).to eq '
|
1164
|
+
expect(row['Date']).to eq first_data_row['Date']
|
1165
|
+
expect(row['Amount']).to eq first_data_row['Amount']
|
1166
|
+
expect(row['Code']).to eq first_data_row['Code']
|
1167
|
+
expect(row['Remark']).to eq first_data_row['Remark']
|
1085
1168
|
expect(row['dummy']).to be_nil
|
1086
1169
|
end
|
1087
1170
|
|
1088
1171
|
it '#parse returns Array of Hash objects' do
|
1089
1172
|
rows = ss.parse
|
1090
1173
|
expect(rows).to be_a Array
|
1091
|
-
expect(rows.size).to eq
|
1174
|
+
expect(rows.size).to eq size_without_headers
|
1092
1175
|
row = rows[0]
|
1093
1176
|
expect(row).to be_a Hash
|
1094
|
-
expect(row['Date']).to eq Date
|
1095
|
-
expect(row['Amount']).to eq
|
1096
|
-
expect(row['Code']).to eq
|
1097
|
-
expect(row['Remark']).to eq '
|
1177
|
+
expect(row['Date']).to eq first_data_row['Date']
|
1178
|
+
expect(row['Amount']).to eq first_data_row['Amount']
|
1179
|
+
expect(row['Code']).to eq first_data_row['Code']
|
1180
|
+
expect(row['Remark']).to eq first_data_row['Remark']
|
1098
1181
|
expect(row['dummy']).to be_nil
|
1099
1182
|
row = rows[13]
|
1100
1183
|
expect(row).to be_a Hash
|
1101
|
-
expect(row['Date']).to eq Date
|
1102
|
-
expect(row['Amount']).to eq
|
1103
|
-
expect(row['Code']).to eq
|
1104
|
-
expect(row['Remark']).to eq '
|
1184
|
+
expect(row['Date']).to eq data_row_13['Date']
|
1185
|
+
expect(row['Amount']).to eq data_row_13['Amount']
|
1186
|
+
expect(row['Code']).to eq data_row_13['Code']
|
1187
|
+
expect(row['Remark']).to eq data_row_13['Remark']
|
1105
1188
|
expect(row['dummy']).to be_nil
|
1106
1189
|
end
|
1107
1190
|
|
@@ -1109,46 +1192,51 @@ describe 'Libis::Tools::Spreadsheet' do
|
|
1109
1192
|
|
1110
1193
|
context 'not specified' do
|
1111
1194
|
|
1112
|
-
let(:required_headers) {
|
1195
|
+
let(:required_headers) {[]}
|
1113
1196
|
|
1114
1197
|
it 'opens correctly' do
|
1115
|
-
expect{
|
1198
|
+
expect {ss}.not_to raise_error
|
1116
1199
|
end
|
1117
1200
|
|
1118
1201
|
it 'contains expected headers' do
|
1119
1202
|
required_headers.each do |header|
|
1120
1203
|
expect(ss.headers).to include header
|
1121
1204
|
end
|
1122
|
-
expect(ss.headers).to eq
|
1205
|
+
expect(ss.headers).to eq real_headers
|
1206
|
+
end
|
1207
|
+
|
1208
|
+
it 'each returns header and data rows' do
|
1209
|
+
expect(ss.each.count).to eq size_with_headers
|
1210
|
+
expect(ss.each.first).to eq header_row
|
1123
1211
|
end
|
1124
1212
|
|
1125
1213
|
it '#shift returns Hash object' do
|
1126
1214
|
row = ss.shift
|
1127
1215
|
expect(row).to be_a Hash
|
1128
|
-
expect(row['Date']).to eq Date
|
1129
|
-
expect(row['Amount']).to eq
|
1130
|
-
expect(row['Code']).to eq
|
1131
|
-
expect(row['Remark']).to eq '
|
1216
|
+
expect(row['Date']).to eq first_data_row['Date']
|
1217
|
+
expect(row['Amount']).to eq first_data_row['Amount']
|
1218
|
+
expect(row['Code']).to eq first_data_row['Code']
|
1219
|
+
expect(row['Remark']).to eq first_data_row['Remark']
|
1132
1220
|
expect(row['dummy']).to be_nil
|
1133
1221
|
end
|
1134
1222
|
|
1135
1223
|
it '#parse returns Array of Hash objects' do
|
1136
1224
|
rows = ss.parse
|
1137
1225
|
expect(rows).to be_a Array
|
1138
|
-
expect(rows.size).to eq
|
1226
|
+
expect(rows.size).to eq size_without_headers
|
1139
1227
|
row = rows[0]
|
1140
1228
|
expect(row).to be_a Hash
|
1141
|
-
expect(row['Date']).to eq Date
|
1142
|
-
expect(row['Amount']).to eq
|
1143
|
-
expect(row['Code']).to eq
|
1144
|
-
expect(row['Remark']).to eq '
|
1229
|
+
expect(row['Date']).to eq first_data_row['Date']
|
1230
|
+
expect(row['Amount']).to eq first_data_row['Amount']
|
1231
|
+
expect(row['Code']).to eq first_data_row['Code']
|
1232
|
+
expect(row['Remark']).to eq first_data_row['Remark']
|
1145
1233
|
expect(row['dummy']).to be_nil
|
1146
1234
|
row = rows[13]
|
1147
1235
|
expect(row).to be_a Hash
|
1148
|
-
expect(row['Date']).to eq Date
|
1149
|
-
expect(row['Amount']).to eq
|
1150
|
-
expect(row['Code']).to eq
|
1151
|
-
expect(row['Remark']).to eq '
|
1236
|
+
expect(row['Date']).to eq data_row_13['Date']
|
1237
|
+
expect(row['Amount']).to eq data_row_13['Amount']
|
1238
|
+
expect(row['Code']).to eq data_row_13['Code']
|
1239
|
+
expect(row['Remark']).to eq data_row_13['Remark']
|
1152
1240
|
expect(row['dummy']).to be_nil
|
1153
1241
|
end
|
1154
1242
|
|
@@ -1156,37 +1244,42 @@ describe 'Libis::Tools::Spreadsheet' do
|
|
1156
1244
|
|
1157
1245
|
context 'not well-formed' do
|
1158
1246
|
|
1159
|
-
let(:required_headers) {
|
1247
|
+
let(:required_headers) {%w'Date dummy1 Amount dummy2'}
|
1160
1248
|
|
1161
1249
|
it 'throws error when opened' do
|
1162
|
-
expect {
|
1250
|
+
expect {ss}.to raise_error(RuntimeError, 'Headers not found: ["dummy1", "dummy2"].')
|
1163
1251
|
end
|
1164
1252
|
end
|
1165
1253
|
|
1166
1254
|
end
|
1167
1255
|
|
1168
1256
|
context 'blank row and columns without headers' do
|
1169
|
-
let(:file_name) {
|
1257
|
+
let(:file_name) {'test.xlsx|ExpensesBlankRowsAndColumnsNoH'}
|
1170
1258
|
|
1171
1259
|
context 'well-formed and strict' do
|
1172
|
-
let(:required_headers) {
|
1260
|
+
let(:required_headers) {%w'Date Amount'}
|
1173
1261
|
|
1174
1262
|
it 'opens correctly' do
|
1175
|
-
expect {
|
1263
|
+
expect {ss}.not_to raise_error
|
1176
1264
|
end
|
1177
1265
|
|
1178
1266
|
it 'contains only required headers' do
|
1179
1267
|
required_headers.each do |header|
|
1180
1268
|
expect(ss.headers).to include header
|
1181
1269
|
end
|
1182
|
-
expect(ss.headers).to eq
|
1270
|
+
expect(ss.headers).to eq required_headers
|
1271
|
+
end
|
1272
|
+
|
1273
|
+
it 'each returns header and data rows' do
|
1274
|
+
expect(ss.each.count).to eq size_with_headers
|
1275
|
+
expect(ss.each.first.keys).to eq required_headers
|
1183
1276
|
end
|
1184
1277
|
|
1185
1278
|
it '#shift returns Hash object' do
|
1186
1279
|
row = ss.shift
|
1187
1280
|
expect(row).to be_a Hash
|
1188
|
-
expect(row['Date']).to eq Date
|
1189
|
-
expect(row['Amount']).to eq
|
1281
|
+
expect(row['Date']).to eq first_data_row['Date']
|
1282
|
+
expect(row['Amount']).to eq first_data_row['Amount']
|
1190
1283
|
expect(row['Code']).to be_nil
|
1191
1284
|
expect(row['Remark']).to be_nil
|
1192
1285
|
expect(row['dummy']).to be_nil
|
@@ -1195,18 +1288,18 @@ describe 'Libis::Tools::Spreadsheet' do
|
|
1195
1288
|
it '#parse returns Array of Hash objects' do
|
1196
1289
|
rows = ss.parse
|
1197
1290
|
expect(rows).to be_a Array
|
1198
|
-
expect(rows.size).to eq
|
1291
|
+
expect(rows.size).to eq size_without_headers
|
1199
1292
|
row = rows[0]
|
1200
1293
|
expect(row).to be_a Hash
|
1201
|
-
expect(row['Date']).to eq Date
|
1202
|
-
expect(row['Amount']).to eq
|
1294
|
+
expect(row['Date']).to eq first_data_row['Date']
|
1295
|
+
expect(row['Amount']).to eq first_data_row['Amount']
|
1203
1296
|
expect(row['Code']).to be_nil
|
1204
1297
|
expect(row['Remark']).to be_nil
|
1205
1298
|
expect(row['dummy']).to be_nil
|
1206
1299
|
row = rows[13]
|
1207
1300
|
expect(row).to be_a Hash
|
1208
|
-
expect(row['Date']).to eq Date
|
1209
|
-
expect(row['Amount']).to eq
|
1301
|
+
expect(row['Date']).to eq data_row_13['Date']
|
1302
|
+
expect(row['Amount']).to eq data_row_13['Amount']
|
1210
1303
|
expect(row['Code']).to be_nil
|
1211
1304
|
expect(row['Remark']).to be_nil
|
1212
1305
|
expect(row['dummy']).to be_nil
|
@@ -1215,11 +1308,11 @@ describe 'Libis::Tools::Spreadsheet' do
|
|
1215
1308
|
end
|
1216
1309
|
|
1217
1310
|
context 'well-formed with optional headers' do
|
1218
|
-
let(:required_headers) {
|
1219
|
-
let(:optional_headers) {
|
1311
|
+
let(:required_headers) {%w'Date Amount'}
|
1312
|
+
let(:optional_headers) {%w'Code'}
|
1220
1313
|
|
1221
1314
|
it 'opens correctly' do
|
1222
|
-
expect {
|
1315
|
+
expect {ss}.not_to raise_error
|
1223
1316
|
end
|
1224
1317
|
|
1225
1318
|
it 'contains required and optional headers' do
|
@@ -1229,15 +1322,20 @@ describe 'Libis::Tools::Spreadsheet' do
|
|
1229
1322
|
optional_headers.each do |header|
|
1230
1323
|
expect(ss.headers).to include header
|
1231
1324
|
end
|
1232
|
-
expect(ss.headers).to eq
|
1325
|
+
expect(ss.headers).to eq required_headers + optional_headers
|
1326
|
+
end
|
1327
|
+
|
1328
|
+
it 'each returns header and data rows' do
|
1329
|
+
expect(ss.each.count).to eq size_with_headers
|
1330
|
+
expect(ss.each.first.keys).to eq required_headers + optional_headers
|
1233
1331
|
end
|
1234
1332
|
|
1235
1333
|
it '#shift returns Hash object' do
|
1236
1334
|
row = ss.shift
|
1237
1335
|
expect(row).to be_a Hash
|
1238
|
-
expect(row['Date']).to eq Date
|
1239
|
-
expect(row['Amount']).to eq
|
1240
|
-
expect(row['Code']).to eq
|
1336
|
+
expect(row['Date']).to eq first_data_row['Date']
|
1337
|
+
expect(row['Amount']).to eq first_data_row['Amount']
|
1338
|
+
expect(row['Code']).to eq first_data_row['Code']
|
1241
1339
|
expect(row['Remark']).to be_nil
|
1242
1340
|
expect(row['dummy']).to be_nil
|
1243
1341
|
end
|
@@ -1245,19 +1343,19 @@ describe 'Libis::Tools::Spreadsheet' do
|
|
1245
1343
|
it '#parse returns Array of Hash objects' do
|
1246
1344
|
rows = ss.parse
|
1247
1345
|
expect(rows).to be_a Array
|
1248
|
-
expect(rows.size).to eq
|
1346
|
+
expect(rows.size).to eq size_without_headers
|
1249
1347
|
row = rows[0]
|
1250
1348
|
expect(row).to be_a Hash
|
1251
|
-
expect(row['Date']).to eq Date
|
1252
|
-
expect(row['Amount']).to eq
|
1253
|
-
expect(row['Code']).to eq
|
1349
|
+
expect(row['Date']).to eq first_data_row['Date']
|
1350
|
+
expect(row['Amount']).to eq first_data_row['Amount']
|
1351
|
+
expect(row['Code']).to eq first_data_row['Code']
|
1254
1352
|
expect(row['Remark']).to be_nil
|
1255
1353
|
expect(row['dummy']).to be_nil
|
1256
1354
|
row = rows[13]
|
1257
1355
|
expect(row).to be_a Hash
|
1258
|
-
expect(row['Date']).to eq Date
|
1259
|
-
expect(row['Amount']).to eq
|
1260
|
-
expect(row['Code']).to eq
|
1356
|
+
expect(row['Date']).to eq data_row_13['Date']
|
1357
|
+
expect(row['Amount']).to eq data_row_13['Amount']
|
1358
|
+
expect(row['Code']).to eq data_row_13['Code']
|
1261
1359
|
expect(row['Remark']).to be_nil
|
1262
1360
|
expect(row['dummy']).to be_nil
|
1263
1361
|
end
|
@@ -1266,11 +1364,11 @@ describe 'Libis::Tools::Spreadsheet' do
|
|
1266
1364
|
|
1267
1365
|
context 'missing optional headers' do
|
1268
1366
|
|
1269
|
-
let(:required_headers) {
|
1270
|
-
let(:optional_headers) {
|
1367
|
+
let(:required_headers) {%w'Date Amount Code Remark'}
|
1368
|
+
let(:optional_headers) {%w'dummy'}
|
1271
1369
|
|
1272
1370
|
it 'opens correctly' do
|
1273
|
-
expect {
|
1371
|
+
expect {ss}.not_to raise_error
|
1274
1372
|
end
|
1275
1373
|
|
1276
1374
|
it 'contains only required headers' do
|
@@ -1280,52 +1378,210 @@ describe 'Libis::Tools::Spreadsheet' do
|
|
1280
1378
|
optional_headers.each do |header|
|
1281
1379
|
expect(ss.headers).not_to include header
|
1282
1380
|
end
|
1283
|
-
expect(ss.headers).to eq
|
1381
|
+
expect(ss.headers).to eq required_headers
|
1382
|
+
end
|
1383
|
+
|
1384
|
+
it 'each returns header and data rows' do
|
1385
|
+
expect(ss.each.count).to eq size_with_headers
|
1386
|
+
expect(ss.each.first.keys).to eq required_headers
|
1284
1387
|
end
|
1285
1388
|
|
1286
1389
|
it '#shift returns Hash object' do
|
1287
1390
|
row = ss.shift
|
1288
1391
|
expect(row).to be_a Hash
|
1289
|
-
expect(row['Date']).to eq Date
|
1290
|
-
expect(row['Amount']).to eq
|
1291
|
-
expect(row['Code']).to eq
|
1292
|
-
expect(row['Remark']).to eq '
|
1392
|
+
expect(row['Date']).to eq first_data_row['Date']
|
1393
|
+
expect(row['Amount']).to eq first_data_row['Amount']
|
1394
|
+
expect(row['Code']).to eq first_data_row['Code']
|
1395
|
+
expect(row['Remark']).to eq first_data_row['Remark']
|
1293
1396
|
expect(row['dummy']).to be_nil
|
1294
1397
|
end
|
1295
1398
|
|
1296
1399
|
it '#parse returns Array of Hash objects' do
|
1297
1400
|
rows = ss.parse
|
1298
1401
|
expect(rows).to be_a Array
|
1299
|
-
expect(rows.size).to eq
|
1402
|
+
expect(rows.size).to eq size_without_headers
|
1300
1403
|
row = rows[0]
|
1301
1404
|
expect(row).to be_a Hash
|
1302
|
-
expect(row['Date']).to eq Date
|
1303
|
-
expect(row['Amount']).to eq
|
1304
|
-
expect(row['Code']).to eq
|
1305
|
-
expect(row['Remark']).to eq '
|
1405
|
+
expect(row['Date']).to eq first_data_row['Date']
|
1406
|
+
expect(row['Amount']).to eq first_data_row['Amount']
|
1407
|
+
expect(row['Code']).to eq first_data_row['Code']
|
1408
|
+
expect(row['Remark']).to eq first_data_row['Remark']
|
1306
1409
|
expect(row['dummy']).to be_nil
|
1307
1410
|
row = rows[13]
|
1308
1411
|
expect(row).to be_a Hash
|
1309
|
-
expect(row['Date']).to eq Date
|
1310
|
-
expect(row['Amount']).to eq
|
1311
|
-
expect(row['Code']).to eq
|
1312
|
-
expect(row['Remark']).to eq '
|
1412
|
+
expect(row['Date']).to eq data_row_13['Date']
|
1413
|
+
expect(row['Amount']).to eq data_row_13['Amount']
|
1414
|
+
expect(row['Code']).to eq data_row_13['Code']
|
1415
|
+
expect(row['Remark']).to eq data_row_13['Remark']
|
1313
1416
|
expect(row['dummy']).to be_nil
|
1314
1417
|
end
|
1315
1418
|
|
1316
1419
|
end
|
1317
1420
|
|
1318
1421
|
context 'missing required header' do
|
1319
|
-
let(:required_headers) {
|
1422
|
+
let(:required_headers) {%w'Date Amount Code Remark dummy'}
|
1320
1423
|
|
1321
1424
|
it 'throws error when opened' do
|
1322
|
-
expect {
|
1425
|
+
expect {ss}.to raise_error(RuntimeError, 'Sheet does not contain enough columns.')
|
1323
1426
|
end
|
1324
1427
|
|
1325
1428
|
end
|
1326
1429
|
|
1327
1430
|
end
|
1328
1431
|
|
1432
|
+
context 'Only headers' do
|
1433
|
+
let(:file_name) {'test.xlsx|ExpensesOnlyHeaders'}
|
1434
|
+
|
1435
|
+
context 'well-formed' do
|
1436
|
+
|
1437
|
+
let(:required_headers) {%w'Date Amount'}
|
1438
|
+
|
1439
|
+
it 'opens correctly' do
|
1440
|
+
expect {ss}.not_to raise_error
|
1441
|
+
end
|
1442
|
+
|
1443
|
+
it 'contains expected headers' do
|
1444
|
+
required_headers.each do |header|
|
1445
|
+
expect(ss.headers).to include header
|
1446
|
+
end
|
1447
|
+
expect(ss.headers).to eq real_headers
|
1448
|
+
end
|
1449
|
+
|
1450
|
+
it 'each returns header and data rows' do
|
1451
|
+
expect(ss.each.count).to be 1
|
1452
|
+
expect(ss.each.first).to eq header_row
|
1453
|
+
end
|
1454
|
+
|
1455
|
+
it '#shift returns nil' do
|
1456
|
+
row = ss.shift
|
1457
|
+
expect(row).to be_nil
|
1458
|
+
end
|
1459
|
+
|
1460
|
+
it '#parse returns empty Array of Hash objects' do
|
1461
|
+
rows = ss.parse
|
1462
|
+
expect(rows).to be_a Array
|
1463
|
+
# noinspection RubyResolve
|
1464
|
+
expect(rows).to be_empty
|
1465
|
+
expect(rows.size).to eq 0
|
1466
|
+
end
|
1467
|
+
|
1468
|
+
end
|
1469
|
+
|
1470
|
+
context 'not specified' do
|
1471
|
+
|
1472
|
+
let(:required_headers) {[]}
|
1473
|
+
|
1474
|
+
it 'opens correctly' do
|
1475
|
+
expect {ss}.not_to raise_error
|
1476
|
+
end
|
1477
|
+
|
1478
|
+
it 'contains expected headers' do
|
1479
|
+
required_headers.each do |header|
|
1480
|
+
expect(ss.headers).to include header
|
1481
|
+
end
|
1482
|
+
expect(ss.headers).to eq %w'Date Amount Code Remark'
|
1483
|
+
end
|
1484
|
+
|
1485
|
+
it '#shift returns nil' do
|
1486
|
+
row = ss.shift
|
1487
|
+
expect(row).to be_nil
|
1488
|
+
end
|
1489
|
+
|
1490
|
+
it '#parse returns empty Array of Hash objects' do
|
1491
|
+
rows = ss.parse
|
1492
|
+
expect(rows).to be_a Array
|
1493
|
+
# noinspection RubyResolve
|
1494
|
+
expect(rows).to be_empty
|
1495
|
+
expect(rows.size).to eq 0
|
1496
|
+
end
|
1497
|
+
|
1498
|
+
end
|
1499
|
+
|
1500
|
+
context 'not well-formed' do
|
1501
|
+
|
1502
|
+
let(:required_headers) {%w'Date dummy1 Amount dummy2'}
|
1503
|
+
|
1504
|
+
it 'throws error when opened' do
|
1505
|
+
expect {ss}.to raise_error(RuntimeError, 'Headers not found: ["dummy1", "dummy2"].')
|
1506
|
+
end
|
1507
|
+
end
|
1508
|
+
|
1509
|
+
end
|
1510
|
+
|
1511
|
+
context 'Only headers with blank rows and columns' do
|
1512
|
+
let(:file_name) {'test.xlsx|ExpensesOnlyHeadersBlankRowsAndColumns'}
|
1513
|
+
|
1514
|
+
context 'well-formed' do
|
1515
|
+
|
1516
|
+
let(:required_headers) {%w'Date Amount'}
|
1517
|
+
|
1518
|
+
it 'opens correctly' do
|
1519
|
+
expect {ss}.not_to raise_error
|
1520
|
+
end
|
1521
|
+
|
1522
|
+
it 'contains expected headers' do
|
1523
|
+
required_headers.each do |header|
|
1524
|
+
expect(ss.headers).to include header
|
1525
|
+
end
|
1526
|
+
expect(ss.headers).to eq %w'Date Amount Code Remark'
|
1527
|
+
end
|
1528
|
+
|
1529
|
+
it '#shift returns nil' do
|
1530
|
+
row = ss.shift
|
1531
|
+
expect(row).to be_nil
|
1532
|
+
end
|
1533
|
+
|
1534
|
+
it '#parse returns empty Array of Hash objects' do
|
1535
|
+
rows = ss.parse
|
1536
|
+
expect(rows).to be_a Array
|
1537
|
+
# noinspection RubyResolve
|
1538
|
+
expect(rows).to be_empty
|
1539
|
+
expect(rows.size).to eq 0
|
1540
|
+
end
|
1541
|
+
|
1542
|
+
end
|
1543
|
+
|
1544
|
+
context 'not specified' do
|
1545
|
+
|
1546
|
+
let(:required_headers) {[]}
|
1547
|
+
|
1548
|
+
it 'opens correctly' do
|
1549
|
+
expect {ss}.not_to raise_error
|
1550
|
+
end
|
1551
|
+
|
1552
|
+
it 'contains expected headers' do
|
1553
|
+
required_headers.each do |header|
|
1554
|
+
expect(ss.headers).to include header
|
1555
|
+
end
|
1556
|
+
expect(ss.headers).to eq %w'Date Amount Code Remark'
|
1557
|
+
end
|
1558
|
+
|
1559
|
+
it '#shift returns nil' do
|
1560
|
+
row = ss.shift
|
1561
|
+
expect(row).to be_nil
|
1562
|
+
end
|
1563
|
+
|
1564
|
+
it '#parse returns empty Array of Hash objects' do
|
1565
|
+
rows = ss.parse
|
1566
|
+
expect(rows).to be_a Array
|
1567
|
+
# noinspection RubyResolve
|
1568
|
+
expect(rows).to be_empty
|
1569
|
+
expect(rows.size).to eq 0
|
1570
|
+
end
|
1571
|
+
|
1572
|
+
end
|
1573
|
+
|
1574
|
+
context 'not well-formed' do
|
1575
|
+
|
1576
|
+
let(:required_headers) {%w'Date dummy1 Amount dummy2'}
|
1577
|
+
|
1578
|
+
it 'throws error when opened' do
|
1579
|
+
expect {ss}.to raise_error(RuntimeError, 'Headers not found: ["dummy1", "dummy2"].')
|
1580
|
+
end
|
1581
|
+
end
|
1582
|
+
|
1583
|
+
end
|
1584
|
+
|
1329
1585
|
end
|
1330
1586
|
|
1331
1587
|
end
|