defoker 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,482 +1,482 @@
1
- # encoding: utf-8
2
- require 'spec_helper'
3
- require 'date_base_name'
4
- require 'date'
5
-
6
- describe Defoker::DateBaseName do
7
- context :to_yyyymmdd do
8
- cases = [
9
- {
10
- case_no: 1,
11
- case_title: 'no addition, 1digit month, 1digit day case',
12
- date: Date.new(2014, 9, 9),
13
- additional: '',
14
- expected: '20140909'
15
- },
16
- {
17
- case_no: 2,
18
- case_title: 'no addition, 2digit month, 1digit day case',
19
- date: Date.new(2014, 12, 9),
20
- additional: '',
21
- expected: '20141209'
22
- },
23
- {
24
- case_no: 3,
25
- case_title: 'no addition, 1digit month, 2digit day case',
26
- date: Date.new(2014, 9, 12),
27
- additional: '',
28
- expected: '20140912'
29
- },
30
- {
31
- case_no: 4,
32
- case_title: 'with addition case',
33
- date: Date.new(2014, 9, 12),
34
- additional: 'hoge',
35
- expected: '20140912_hoge'
36
- },
37
- {
38
- case_no: 5,
39
- case_title: 'omit addition case',
40
- date: Date.new(2014, 9, 12),
41
- additional: nil,
42
- expected: '20140912'
43
- },
44
- {
45
- case_no: 6,
46
- case_title: 'invalid date case',
47
- date: '20140912',
48
- expect_error: true
49
- },
50
- {
51
- case_no: 7,
52
- case_title: 'datetime case',
53
- date: DateTime.new(2014, 9, 12),
54
- additional: nil,
55
- expected: '20140912'
56
- }
57
- ]
58
-
59
- cases.each do |c|
60
- it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
61
- begin
62
- case_before c
63
-
64
- # -- given --
65
- defoker = Defoker::DateBaseName.new
66
-
67
- # -- when --
68
- actual =
69
- if c[:additional]
70
- defoker.to_yyyymmdd(c[:date], additional: c[:additional])
71
- else
72
- if c[:expect_error]
73
- expect { defoker.to_yyyymmdd(c[:date]) }.to raise_error(ArgumentError)
74
- next
75
- end
76
- defoker.to_yyyymmdd(c[:date])
77
- end
78
-
79
- # -- then --
80
- expect(actual).to eq(c[:expected])
81
- ensure
82
- case_after c
83
- end
84
- end
85
-
86
- def case_before(c)
87
- # implement each case before
88
- end
89
-
90
- def case_after(c)
91
- # implement each case after
92
- end
93
- end
94
- end
95
-
96
- context :to_yyyymmdd_list do
97
- cases = [
98
- {
99
- case_no: 1,
100
- case_title: 'no addition 4days case',
101
- day: Date.new(2014, 9, 9),
102
- count: 4,
103
- expected: %w(20140909 20140910 20140911 20140912)
104
- },
105
- {
106
- case_no: 2,
107
- case_title: 'no addition 1day case',
108
- day: Date.new(2014, 9, 12),
109
- count: 1,
110
- expected: ['20140912']
111
- },
112
- {
113
- case_no: 3,
114
- case_title: 'with addition 4days case',
115
- day: Date.new(2014, 9, 9),
116
- count: 4,
117
- additional: 'hoge',
118
- expected: %w(20140909_hoge 20140910_hoge 20140911_hoge 20140912_hoge)
119
- },
120
- {
121
- case_no: 4,
122
- case_title: 'invalid date case',
123
- day: '20140912',
124
- expect_error: true
125
- }
126
- ]
127
-
128
- cases.each do |c|
129
- it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
130
- begin
131
- case_before c
132
-
133
- # -- given --
134
- defoker = Defoker::DateBaseName.new
135
-
136
- # -- when --
137
- actual =
138
- if c[:count] && c[:additional]
139
- defoker.to_yyyymmdd_list(c[:day], count: c[:count], additional: c[:additional])
140
- elsif c[:count]
141
- defoker.to_yyyymmdd_list(c[:day], count: c[:count])
142
- elsif c[:additional]
143
- defoker.to_yyyymmdd_list(c[:day], additional: c[:additional])
144
- else
145
- if c[:expect_error]
146
- expect { defoker.to_yyyymmdd_list(c[:day]) }.to raise_error(ArgumentError)
147
- next
148
- end
149
- defoker.to_yyyymmdd_list(c[:day])
150
- end
151
-
152
- # -- then --
153
- expect(actual).to eq(c[:expected])
154
- ensure
155
- case_after c
156
- end
157
- end
158
-
159
- def case_before(c)
160
- # implement each case before
161
- end
162
-
163
- def case_after(c)
164
- # implement each case after
165
- end
166
- end
167
- end
168
-
169
- context :to_yyyymm do
170
- cases = [
171
- {
172
- case_no: 1,
173
- case_title: 'no addition, 1digit month',
174
- month: Date.new(2014, 9),
175
- additional: '',
176
- expected: '201409'
177
- },
178
- {
179
- case_no: 2,
180
- case_title: 'no addition, 2digit month',
181
- month: Date.new(2014, 12),
182
- additional: '',
183
- expected: '201412'
184
- },
185
- {
186
- case_no: 4,
187
- case_title: 'with addition case',
188
- month: Date.new(2014, 9),
189
- additional: 'hoge',
190
- expected: '201409_hoge'
191
- },
192
- {
193
- case_no: 5,
194
- case_title: 'omit addition case',
195
- month: Date.new(2014, 9),
196
- additional: nil,
197
- expected: '201409'
198
- },
199
- {
200
- case_no: 6,
201
- case_title: 'invalid month case',
202
- month: '201409',
203
- expect_error: true
204
- },
205
- {
206
- case_no: 7,
207
- case_title: 'datetime case',
208
- month: DateTime.new(2014, 9),
209
- additional: nil,
210
- expected: '201409'
211
- }
212
- ]
213
-
214
- cases.each do |c|
215
- it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
216
- begin
217
- case_before c
218
-
219
- # -- given --
220
- defoker = Defoker::DateBaseName.new
221
-
222
- # -- when --
223
- actual =
224
- if c[:additional]
225
- defoker.to_yyyymm(c[:month], additional: c[:additional])
226
- else
227
- if c[:expect_error]
228
- expect { defoker.to_yyyymm(c[:month]) }.to raise_error(ArgumentError)
229
- next
230
- end
231
- defoker.to_yyyymm(c[:month])
232
- end
233
-
234
- # -- then --
235
- expect(actual).to eq(c[:expected])
236
- ensure
237
- case_after c
238
- end
239
- end
240
-
241
- def case_before(c)
242
- # implement each case before
243
- end
244
-
245
- def case_after(c)
246
- # implement each case after
247
- end
248
- end
249
- end
250
-
251
- context :to_yyyymm_list do
252
- cases = [
253
- {
254
- case_no: 1,
255
- case_title: 'no addition 4months case',
256
- month: Date.new(2014, 10),
257
- count: 4,
258
- expected: %w(201410 201411 201412 201501)
259
- },
260
- {
261
- case_no: 2,
262
- case_title: 'no addition 1month case',
263
- month: Date.new(2014, 9),
264
- count: 1,
265
- expected: ['201409']
266
- },
267
- {
268
- case_no: 3,
269
- case_title: 'with addition 4months case',
270
- month: Date.new(2014, 10),
271
- count: 4,
272
- additional: 'hoge',
273
- expected: %w(201410_hoge 201411_hoge 201412_hoge 201501_hoge)
274
- },
275
- {
276
- case_no: 4,
277
- case_title: 'no addition, no count, 3months case',
278
- month: Date.new(2014, 10),
279
- expected: %w(201410 201411 201412)
280
- },
281
- {
282
- case_no: 5,
283
- case_title: 'invalid month case',
284
- month: '201409',
285
- expect_error: true
286
- }
287
- ]
288
-
289
- cases.each do |c|
290
- it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
291
- begin
292
- case_before c
293
-
294
- # -- given --
295
- defoker = Defoker::DateBaseName.new
296
-
297
- # -- when --
298
- actual =
299
- if c[:count] && c[:additional]
300
- defoker.to_yyyymm_list(c[:month], count: c[:count], additional: c[:additional])
301
- elsif c[:count]
302
- defoker.to_yyyymm_list(c[:month], count: c[:count])
303
- elsif c[:additional]
304
- defoker.to_yyyymm_list(c[:month], additional: c[:additional])
305
- else
306
- if c[:expect_error]
307
- expect { defoker.to_yyyymm_list(c[:month]) }.to raise_error(ArgumentError)
308
- next
309
- end
310
- defoker.to_yyyymm_list(c[:month])
311
- end
312
-
313
- # -- then --
314
- expect(actual).to eq(c[:expected])
315
- ensure
316
- case_after c
317
- end
318
- end
319
-
320
- def case_before(c)
321
- # implement each case before
322
- end
323
-
324
- def case_after(c)
325
- # implement each case after
326
- end
327
- end
328
- end
329
-
330
- context :to_yyyy do
331
- cases = [
332
- {
333
- case_no: 1,
334
- case_title: 'no addition case',
335
- year: Date.new(2014),
336
- additional: '',
337
- expected: '2014'
338
- },
339
- {
340
- case_no: 2,
341
- case_title: 'with addition case',
342
- year: Date.new(2014),
343
- additional: 'hoge',
344
- expected: '2014_hoge'
345
- },
346
- {
347
- case_no: 3,
348
- case_title: 'omit addition case',
349
- year: Date.new(2014),
350
- expected: '2014'
351
- },
352
- {
353
- case_no: 4,
354
- case_title: 'invalid year case',
355
- year: '2014',
356
- expect_error: true
357
- },
358
- {
359
- case_no: 5,
360
- case_title: 'datetime case',
361
- year: DateTime.new(2014),
362
- additional: nil,
363
- expected: '2014'
364
- }
365
- ]
366
-
367
- cases.each do |c|
368
- it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
369
- begin
370
- case_before c
371
-
372
- # -- given --
373
- defoker = Defoker::DateBaseName.new
374
-
375
- # -- when --
376
- actual =
377
- if c[:additional]
378
- defoker.to_yyyy(c[:year], additional: c[:additional])
379
- else
380
- if c[:expect_error]
381
- expect { defoker.to_yyyy(c[:year]) }.to raise_error(ArgumentError)
382
- next
383
- end
384
- defoker.to_yyyy(c[:year])
385
- end
386
-
387
- # -- then --
388
- expect(actual).to eq(c[:expected])
389
- ensure
390
- case_after c
391
- end
392
- end
393
-
394
- def case_before(c)
395
- # implement each case before
396
- end
397
-
398
- def case_after(c)
399
- # implement each case after
400
- end
401
- end
402
- end
403
-
404
- context :to_yyyy_list do
405
- cases = [
406
- {
407
- case_no: 1,
408
- case_title: 'no addition 4years case',
409
- year: Date.new(2014),
410
- count: 4,
411
- expected: %w(2014 2015 2016 2017)
412
- },
413
- {
414
- case_no: 2,
415
- case_title: 'no addition 1year case',
416
- year: Date.new(2014),
417
- count: 1,
418
- expected: ['2014']
419
- },
420
- {
421
- case_no: 3,
422
- case_title: 'with addition 4years case',
423
- year: Date.new(2014, 10),
424
- count: 4,
425
- additional: 'hoge',
426
- expected: %w(2014_hoge 2015_hoge 2016_hoge 2017_hoge)
427
- },
428
- {
429
- case_no: 4,
430
- case_title: 'no addition, no count, 3years case',
431
- year: Date.new(2014),
432
- expected: %w(2014 2015 2016)
433
- },
434
- {
435
- case_no: 5,
436
- case_title: 'invalid year case',
437
- from_or_range: '2014',
438
- expect_error: true
439
- }
440
- ]
441
-
442
- cases.each do |c|
443
- it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
444
- begin
445
- case_before c
446
-
447
- # -- given --
448
- defoker = Defoker::DateBaseName.new
449
-
450
- # -- when --
451
- actual =
452
- if c[:count] && c[:additional]
453
- defoker.to_yyyy_list(c[:year], count: c[:count], additional: c[:additional])
454
- elsif c[:count]
455
- defoker.to_yyyy_list(c[:year], count: c[:count])
456
- elsif c[:additional]
457
- defoker.to_yyyy_list(c[:year], additional: c[:additional])
458
- else
459
- if c[:expect_error]
460
- expect { defoker.to_yyyy_list(c[:year]) }.to raise_error(ArgumentError)
461
- next
462
- end
463
- defoker.to_yyyy_list(c[:year])
464
- end
465
-
466
- # -- then --
467
- expect(actual).to eq(c[:expected])
468
- ensure
469
- case_after c
470
- end
471
- end
472
-
473
- def case_before(c)
474
- # implement each case before
475
- end
476
-
477
- def case_after(c)
478
- # implement each case after
479
- end
480
- end
481
- end
482
- end
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+ require 'date_base_name'
4
+ require 'date'
5
+
6
+ describe Defoker::DateBaseName do
7
+ context :to_yyyymmdd do
8
+ cases = [
9
+ {
10
+ case_no: 1,
11
+ case_title: 'no addition, 1digit month, 1digit day case',
12
+ date: Date.new(2014, 9, 9),
13
+ additional: '',
14
+ expected: '20140909'
15
+ },
16
+ {
17
+ case_no: 2,
18
+ case_title: 'no addition, 2digit month, 1digit day case',
19
+ date: Date.new(2014, 12, 9),
20
+ additional: '',
21
+ expected: '20141209'
22
+ },
23
+ {
24
+ case_no: 3,
25
+ case_title: 'no addition, 1digit month, 2digit day case',
26
+ date: Date.new(2014, 9, 12),
27
+ additional: '',
28
+ expected: '20140912'
29
+ },
30
+ {
31
+ case_no: 4,
32
+ case_title: 'with addition case',
33
+ date: Date.new(2014, 9, 12),
34
+ additional: 'hoge',
35
+ expected: '20140912_hoge'
36
+ },
37
+ {
38
+ case_no: 5,
39
+ case_title: 'omit addition case',
40
+ date: Date.new(2014, 9, 12),
41
+ additional: nil,
42
+ expected: '20140912'
43
+ },
44
+ {
45
+ case_no: 6,
46
+ case_title: 'invalid date case',
47
+ date: '20140912',
48
+ expect_error: true
49
+ },
50
+ {
51
+ case_no: 7,
52
+ case_title: 'datetime case',
53
+ date: DateTime.new(2014, 9, 12),
54
+ additional: nil,
55
+ expected: '20140912'
56
+ }
57
+ ]
58
+
59
+ cases.each do |c|
60
+ it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
61
+ begin
62
+ case_before c
63
+
64
+ # -- given --
65
+ # nothing
66
+
67
+ # -- when --
68
+ actual =
69
+ if c[:additional]
70
+ Defoker::DateBaseName.to_yyyymmdd(c[:date], additional: c[:additional])
71
+ else
72
+ if c[:expect_error]
73
+ expect { Defoker::DateBaseName.to_yyyymmdd(c[:date]) }.to raise_error(ArgumentError)
74
+ next
75
+ end
76
+ Defoker::DateBaseName.to_yyyymmdd(c[:date])
77
+ end
78
+
79
+ # -- then --
80
+ expect(actual).to eq(c[:expected])
81
+ ensure
82
+ case_after c
83
+ end
84
+ end
85
+
86
+ def case_before(c)
87
+ # implement each case before
88
+ end
89
+
90
+ def case_after(c)
91
+ # implement each case after
92
+ end
93
+ end
94
+ end
95
+
96
+ context :to_yyyymmdd_list do
97
+ cases = [
98
+ {
99
+ case_no: 1,
100
+ case_title: 'no addition 4days case',
101
+ day: Date.new(2014, 9, 9),
102
+ count: 4,
103
+ expected: %w(20140909 20140910 20140911 20140912)
104
+ },
105
+ {
106
+ case_no: 2,
107
+ case_title: 'no addition 1day case',
108
+ day: Date.new(2014, 9, 12),
109
+ count: 1,
110
+ expected: ['20140912']
111
+ },
112
+ {
113
+ case_no: 3,
114
+ case_title: 'with addition 4days case',
115
+ day: Date.new(2014, 9, 9),
116
+ count: 4,
117
+ additional: 'hoge',
118
+ expected: %w(20140909_hoge 20140910_hoge 20140911_hoge 20140912_hoge)
119
+ },
120
+ {
121
+ case_no: 4,
122
+ case_title: 'invalid date case',
123
+ day: '20140912',
124
+ expect_error: true
125
+ }
126
+ ]
127
+
128
+ cases.each do |c|
129
+ it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
130
+ begin
131
+ case_before c
132
+
133
+ # -- given --
134
+ # nothing
135
+
136
+ # -- when --
137
+ actual =
138
+ if c[:count] && c[:additional]
139
+ Defoker::DateBaseName.to_yyyymmdd_list(c[:day], count: c[:count], additional: c[:additional])
140
+ elsif c[:count]
141
+ Defoker::DateBaseName.to_yyyymmdd_list(c[:day], count: c[:count])
142
+ elsif c[:additional]
143
+ Defoker::DateBaseName.to_yyyymmdd_list(c[:day], additional: c[:additional])
144
+ else
145
+ if c[:expect_error]
146
+ expect { Defoker::DateBaseName.to_yyyymmdd_list(c[:day]) }.to raise_error(ArgumentError)
147
+ next
148
+ end
149
+ Defoker::DateBaseName.to_yyyymmdd_list(c[:day])
150
+ end
151
+
152
+ # -- then --
153
+ expect(actual).to eq(c[:expected])
154
+ ensure
155
+ case_after c
156
+ end
157
+ end
158
+
159
+ def case_before(c)
160
+ # implement each case before
161
+ end
162
+
163
+ def case_after(c)
164
+ # implement each case after
165
+ end
166
+ end
167
+ end
168
+
169
+ context :to_yyyymm do
170
+ cases = [
171
+ {
172
+ case_no: 1,
173
+ case_title: 'no addition, 1digit month',
174
+ month: Date.new(2014, 9),
175
+ additional: '',
176
+ expected: '201409'
177
+ },
178
+ {
179
+ case_no: 2,
180
+ case_title: 'no addition, 2digit month',
181
+ month: Date.new(2014, 12),
182
+ additional: '',
183
+ expected: '201412'
184
+ },
185
+ {
186
+ case_no: 4,
187
+ case_title: 'with addition case',
188
+ month: Date.new(2014, 9),
189
+ additional: 'hoge',
190
+ expected: '201409_hoge'
191
+ },
192
+ {
193
+ case_no: 5,
194
+ case_title: 'omit addition case',
195
+ month: Date.new(2014, 9),
196
+ additional: nil,
197
+ expected: '201409'
198
+ },
199
+ {
200
+ case_no: 6,
201
+ case_title: 'invalid month case',
202
+ month: '201409',
203
+ expect_error: true
204
+ },
205
+ {
206
+ case_no: 7,
207
+ case_title: 'datetime case',
208
+ month: DateTime.new(2014, 9),
209
+ additional: nil,
210
+ expected: '201409'
211
+ }
212
+ ]
213
+
214
+ cases.each do |c|
215
+ it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
216
+ begin
217
+ case_before c
218
+
219
+ # -- given --
220
+ # nothing
221
+
222
+ # -- when --
223
+ actual =
224
+ if c[:additional]
225
+ Defoker::DateBaseName.to_yyyymm(c[:month], additional: c[:additional])
226
+ else
227
+ if c[:expect_error]
228
+ expect { Defoker::DateBaseName.to_yyyymm(c[:month]) }.to raise_error(ArgumentError)
229
+ next
230
+ end
231
+ Defoker::DateBaseName.to_yyyymm(c[:month])
232
+ end
233
+
234
+ # -- then --
235
+ expect(actual).to eq(c[:expected])
236
+ ensure
237
+ case_after c
238
+ end
239
+ end
240
+
241
+ def case_before(c)
242
+ # implement each case before
243
+ end
244
+
245
+ def case_after(c)
246
+ # implement each case after
247
+ end
248
+ end
249
+ end
250
+
251
+ context :to_yyyymm_list do
252
+ cases = [
253
+ {
254
+ case_no: 1,
255
+ case_title: 'no addition 4months case',
256
+ month: Date.new(2014, 10),
257
+ count: 4,
258
+ expected: %w(201410 201411 201412 201501)
259
+ },
260
+ {
261
+ case_no: 2,
262
+ case_title: 'no addition 1month case',
263
+ month: Date.new(2014, 9),
264
+ count: 1,
265
+ expected: ['201409']
266
+ },
267
+ {
268
+ case_no: 3,
269
+ case_title: 'with addition 4months case',
270
+ month: Date.new(2014, 10),
271
+ count: 4,
272
+ additional: 'hoge',
273
+ expected: %w(201410_hoge 201411_hoge 201412_hoge 201501_hoge)
274
+ },
275
+ {
276
+ case_no: 4,
277
+ case_title: 'no addition, no count, 3months case',
278
+ month: Date.new(2014, 10),
279
+ expected: %w(201410 201411 201412)
280
+ },
281
+ {
282
+ case_no: 5,
283
+ case_title: 'invalid month case',
284
+ month: '201409',
285
+ expect_error: true
286
+ }
287
+ ]
288
+
289
+ cases.each do |c|
290
+ it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
291
+ begin
292
+ case_before c
293
+
294
+ # -- given --
295
+ # nothing
296
+
297
+ # -- when --
298
+ actual =
299
+ if c[:count] && c[:additional]
300
+ Defoker::DateBaseName.to_yyyymm_list(c[:month], count: c[:count], additional: c[:additional])
301
+ elsif c[:count]
302
+ Defoker::DateBaseName.to_yyyymm_list(c[:month], count: c[:count])
303
+ elsif c[:additional]
304
+ Defoker::DateBaseName.to_yyyymm_list(c[:month], additional: c[:additional])
305
+ else
306
+ if c[:expect_error]
307
+ expect { Defoker::DateBaseName.to_yyyymm_list(c[:month]) }.to raise_error(ArgumentError)
308
+ next
309
+ end
310
+ Defoker::DateBaseName.to_yyyymm_list(c[:month])
311
+ end
312
+
313
+ # -- then --
314
+ expect(actual).to eq(c[:expected])
315
+ ensure
316
+ case_after c
317
+ end
318
+ end
319
+
320
+ def case_before(c)
321
+ # implement each case before
322
+ end
323
+
324
+ def case_after(c)
325
+ # implement each case after
326
+ end
327
+ end
328
+ end
329
+
330
+ context :to_yyyy do
331
+ cases = [
332
+ {
333
+ case_no: 1,
334
+ case_title: 'no addition case',
335
+ year: Date.new(2014),
336
+ additional: '',
337
+ expected: '2014'
338
+ },
339
+ {
340
+ case_no: 2,
341
+ case_title: 'with addition case',
342
+ year: Date.new(2014),
343
+ additional: 'hoge',
344
+ expected: '2014_hoge'
345
+ },
346
+ {
347
+ case_no: 3,
348
+ case_title: 'omit addition case',
349
+ year: Date.new(2014),
350
+ expected: '2014'
351
+ },
352
+ {
353
+ case_no: 4,
354
+ case_title: 'invalid year case',
355
+ year: '2014',
356
+ expect_error: true
357
+ },
358
+ {
359
+ case_no: 5,
360
+ case_title: 'datetime case',
361
+ year: DateTime.new(2014),
362
+ additional: nil,
363
+ expected: '2014'
364
+ }
365
+ ]
366
+
367
+ cases.each do |c|
368
+ it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
369
+ begin
370
+ case_before c
371
+
372
+ # -- given --
373
+ # nothing
374
+
375
+ # -- when --
376
+ actual =
377
+ if c[:additional]
378
+ Defoker::DateBaseName.to_yyyy(c[:year], additional: c[:additional])
379
+ else
380
+ if c[:expect_error]
381
+ expect { Defoker::DateBaseName.to_yyyy(c[:year]) }.to raise_error(ArgumentError)
382
+ next
383
+ end
384
+ Defoker::DateBaseName.to_yyyy(c[:year])
385
+ end
386
+
387
+ # -- then --
388
+ expect(actual).to eq(c[:expected])
389
+ ensure
390
+ case_after c
391
+ end
392
+ end
393
+
394
+ def case_before(c)
395
+ # implement each case before
396
+ end
397
+
398
+ def case_after(c)
399
+ # implement each case after
400
+ end
401
+ end
402
+ end
403
+
404
+ context :to_yyyy_list do
405
+ cases = [
406
+ {
407
+ case_no: 1,
408
+ case_title: 'no addition 4years case',
409
+ year: Date.new(2014),
410
+ count: 4,
411
+ expected: %w(2014 2015 2016 2017)
412
+ },
413
+ {
414
+ case_no: 2,
415
+ case_title: 'no addition 1year case',
416
+ year: Date.new(2014),
417
+ count: 1,
418
+ expected: ['2014']
419
+ },
420
+ {
421
+ case_no: 3,
422
+ case_title: 'with addition 4years case',
423
+ year: Date.new(2014, 10),
424
+ count: 4,
425
+ additional: 'hoge',
426
+ expected: %w(2014_hoge 2015_hoge 2016_hoge 2017_hoge)
427
+ },
428
+ {
429
+ case_no: 4,
430
+ case_title: 'no addition, no count, 3years case',
431
+ year: Date.new(2014),
432
+ expected: %w(2014 2015 2016)
433
+ },
434
+ {
435
+ case_no: 5,
436
+ case_title: 'invalid year case',
437
+ from_or_range: '2014',
438
+ expect_error: true
439
+ }
440
+ ]
441
+
442
+ cases.each do |c|
443
+ it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
444
+ begin
445
+ case_before c
446
+
447
+ # -- given --
448
+ # nothing
449
+
450
+ # -- when --
451
+ actual =
452
+ if c[:count] && c[:additional]
453
+ Defoker::DateBaseName.to_yyyy_list(c[:year], count: c[:count], additional: c[:additional])
454
+ elsif c[:count]
455
+ Defoker::DateBaseName.to_yyyy_list(c[:year], count: c[:count])
456
+ elsif c[:additional]
457
+ Defoker::DateBaseName.to_yyyy_list(c[:year], additional: c[:additional])
458
+ else
459
+ if c[:expect_error]
460
+ expect { Defoker::DateBaseName.to_yyyy_list(c[:year]) }.to raise_error(ArgumentError)
461
+ next
462
+ end
463
+ Defoker::DateBaseName.to_yyyy_list(c[:year])
464
+ end
465
+
466
+ # -- then --
467
+ expect(actual).to eq(c[:expected])
468
+ ensure
469
+ case_after c
470
+ end
471
+ end
472
+
473
+ def case_before(c)
474
+ # implement each case before
475
+ end
476
+
477
+ def case_after(c)
478
+ # implement each case after
479
+ end
480
+ end
481
+ end
482
+ end