defoker 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,609 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+ require 'defoker_core'
4
+ require 'timecop'
5
+
6
+ describe Defoker::Core do
7
+ context :today do
8
+ cases = [
9
+ {
10
+ case_no: 1,
11
+ case_title: 'no additional case',
12
+ dummy_year: 2014,
13
+ dummy_month: 9,
14
+ dummy_day: 1,
15
+ additional: '',
16
+ expected: '20140901'
17
+ },
18
+ {
19
+ case_no: 2,
20
+ case_title: 'with additional case',
21
+ dummy_year: 2014,
22
+ dummy_month: 9,
23
+ dummy_day: 1,
24
+ additional: 'hoge',
25
+ expected: '20140901_hoge'
26
+ }
27
+ ]
28
+
29
+ cases.each do |c|
30
+ it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
31
+ begin
32
+ case_before c
33
+
34
+ # -- given --
35
+ defoker_core = Defoker::Core.new
36
+ Timecop.freeze(Time.local(c[:dummy_year], c[:dummy_month], c[:dummy_day]))
37
+
38
+ # -- when --
39
+ actual = defoker_core.today(additional: c[:additional])
40
+
41
+ # -- then --
42
+ expect(actual).to eq(c[:expected])
43
+ ensure
44
+ case_after c
45
+ end
46
+ end
47
+
48
+ def case_before(c)
49
+ # implement each case before
50
+ end
51
+
52
+ def case_after(c)
53
+ # implement each case after
54
+ end
55
+ end
56
+ end
57
+
58
+ context :tommorow do
59
+ cases = [
60
+ {
61
+ case_no: 1,
62
+ case_title: 'no additional case',
63
+ dummy_year: 2014,
64
+ dummy_month: 9,
65
+ dummy_day: 1,
66
+ additional: '',
67
+ expected: '20140902'
68
+ },
69
+ {
70
+ case_no: 2,
71
+ case_title: 'with additional case',
72
+ dummy_year: 2014,
73
+ dummy_month: 9,
74
+ dummy_day: 1,
75
+ additional: 'hoge',
76
+ expected: '20140902_hoge'
77
+ }
78
+ ]
79
+
80
+ cases.each do |c|
81
+ it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
82
+ begin
83
+ case_before c
84
+
85
+ # -- given --
86
+ defoker_core = Defoker::Core.new
87
+ Timecop.travel(Time.local(c[:dummy_year], c[:dummy_month], c[:dummy_day]))
88
+
89
+ # -- when --
90
+ actual = defoker_core.tommorow(additional: c[:additional])
91
+
92
+ # -- then --
93
+ expect(actual).to eq(c[:expected])
94
+ ensure
95
+ case_after c
96
+ end
97
+ end
98
+
99
+ def case_before(c)
100
+ # implement each case before
101
+ end
102
+
103
+ def case_after(c)
104
+ # implement each case after
105
+ end
106
+ end
107
+ end
108
+
109
+ context :yesterday do
110
+ cases = [
111
+ {
112
+ case_no: 1,
113
+ case_title: 'no additional case',
114
+ dummy_year: 2014,
115
+ dummy_month: 9,
116
+ dummy_day: 1,
117
+ additional: '',
118
+ expected: '20140831'
119
+ },
120
+ {
121
+ case_no: 2,
122
+ case_title: 'with additional case',
123
+ dummy_year: 2014,
124
+ dummy_month: 9,
125
+ dummy_day: 1,
126
+ additional: 'hoge',
127
+ expected: '20140831_hoge'
128
+ }
129
+ ]
130
+
131
+ cases.each do |c|
132
+ it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
133
+ begin
134
+ case_before c
135
+
136
+ # -- given --
137
+ defoker_core = Defoker::Core.new
138
+ Timecop.travel(Time.local(c[:dummy_year], c[:dummy_month], c[:dummy_day]))
139
+
140
+ # -- when --
141
+ actual = defoker_core.yesterday(additional: c[:additional])
142
+
143
+ # -- then --
144
+ expect(actual).to eq(c[:expected])
145
+ ensure
146
+ case_after c
147
+ end
148
+ end
149
+
150
+ def case_before(c)
151
+ # implement each case before
152
+ end
153
+
154
+ def case_after(c)
155
+ # implement each case after
156
+ end
157
+ end
158
+ end
159
+
160
+ context :days do
161
+ cases = [
162
+ {
163
+ case_no: 1,
164
+ case_title: 'no additional case',
165
+ date: '20140909',
166
+ count: 4,
167
+ additional: '',
168
+ expected: %w(20140909 20140910 20140911 20140912)
169
+ },
170
+ {
171
+ case_no: 2,
172
+ case_title: 'with additional case',
173
+ date: '20140909',
174
+ count: 4,
175
+ additional: 'hoge',
176
+ expected: %w(20140909_hoge 20140910_hoge 20140911_hoge 20140912_hoge)
177
+ }
178
+ ]
179
+
180
+ cases.each do |c|
181
+ it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
182
+ begin
183
+ case_before c
184
+
185
+ # -- given --
186
+ defoker_core = Defoker::Core.new
187
+
188
+ # -- when --
189
+ actual = defoker_core.days(c[:date], count: c[:count], additional: c[:additional])
190
+
191
+ # -- then --
192
+ expect(actual).to eq(c[:expected])
193
+ ensure
194
+ case_after c
195
+ end
196
+ end
197
+
198
+ def case_before(c)
199
+ # implement each case before
200
+ end
201
+
202
+ def case_after(c)
203
+ # implement each case after
204
+ end
205
+ end
206
+ end
207
+
208
+ context :this_month do
209
+ cases = [
210
+ {
211
+ case_no: 1,
212
+ case_title: 'no additional case',
213
+ dummy_year: 2014,
214
+ dummy_month: 9,
215
+ dummy_day: 1,
216
+ additional: '',
217
+ expected: '201409'
218
+ },
219
+ {
220
+ case_no: 2,
221
+ case_title: 'with additional case',
222
+ dummy_year: 2014,
223
+ dummy_month: 9,
224
+ dummy_day: 1,
225
+ additional: 'hoge',
226
+ expected: '201409_hoge'
227
+ }
228
+ ]
229
+
230
+ cases.each do |c|
231
+ it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
232
+ begin
233
+ case_before c
234
+
235
+ # -- given --
236
+ defoker_core = Defoker::Core.new
237
+ Timecop.freeze(Time.local(c[:dummy_year], c[:dummy_month], c[:dummy_day]))
238
+
239
+ # -- when --
240
+ actual = defoker_core.this_month(additional: c[:additional])
241
+
242
+ # -- then --
243
+ expect(actual).to eq(c[:expected])
244
+ ensure
245
+ case_after c
246
+ end
247
+ end
248
+
249
+ def case_before(c)
250
+ # implement each case before
251
+ end
252
+
253
+ def case_after(c)
254
+ # implement each case after
255
+ end
256
+ end
257
+ end
258
+
259
+ context :next_month do
260
+ cases = [
261
+ {
262
+ case_no: 1,
263
+ case_title: 'no additional case',
264
+ dummy_year: 2014,
265
+ dummy_month: 9,
266
+ dummy_day: 1,
267
+ additional: '',
268
+ expected: '201410'
269
+ },
270
+ {
271
+ case_no: 2,
272
+ case_title: 'with additional case',
273
+ dummy_year: 2014,
274
+ dummy_month: 9,
275
+ dummy_day: 1,
276
+ additional: 'hoge',
277
+ expected: '201410_hoge'
278
+ }
279
+ ]
280
+
281
+ cases.each do |c|
282
+ it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
283
+ begin
284
+ case_before c
285
+
286
+ # -- given --
287
+ defoker_core = Defoker::Core.new
288
+ Timecop.freeze(Time.local(c[:dummy_year], c[:dummy_month], c[:dummy_day]))
289
+
290
+ # -- when --
291
+ actual = defoker_core.next_month(additional: c[:additional])
292
+
293
+ # -- then --
294
+ expect(actual).to eq(c[:expected])
295
+ ensure
296
+ case_after c
297
+ end
298
+ end
299
+
300
+ def case_before(c)
301
+ # implement each case before
302
+ end
303
+
304
+ def case_after(c)
305
+ # implement each case after
306
+ end
307
+ end
308
+ end
309
+
310
+ context :previous_month do
311
+ cases = [
312
+ {
313
+ case_no: 1,
314
+ case_title: 'no additional case',
315
+ dummy_year: 2014,
316
+ dummy_month: 9,
317
+ dummy_day: 1,
318
+ additional: '',
319
+ expected: '201408'
320
+ },
321
+ {
322
+ case_no: 2,
323
+ case_title: 'with additional case',
324
+ dummy_year: 2014,
325
+ dummy_month: 9,
326
+ dummy_day: 1,
327
+ additional: 'hoge',
328
+ expected: '201408_hoge'
329
+ }
330
+ ]
331
+
332
+ cases.each do |c|
333
+ it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
334
+ begin
335
+ case_before c
336
+
337
+ # -- given --
338
+ defoker_core = Defoker::Core.new
339
+ Timecop.freeze(Time.local(c[:dummy_year], c[:dummy_month], c[:dummy_day]))
340
+
341
+ # -- when --
342
+ actual = defoker_core.previous_month(additional: c[:additional])
343
+
344
+ # -- then --
345
+ expect(actual).to eq(c[:expected])
346
+ ensure
347
+ case_after c
348
+ end
349
+ end
350
+
351
+ def case_before(c)
352
+ # implement each case before
353
+ end
354
+
355
+ def case_after(c)
356
+ # implement each case after
357
+ end
358
+ end
359
+ end
360
+
361
+ context :months do
362
+ cases = [
363
+ {
364
+ case_no: 1,
365
+ case_title: 'no additional case',
366
+ month: '201410',
367
+ count: 4,
368
+ additional: '',
369
+ expected: %w(201410 201411 201412 201501)
370
+ },
371
+ {
372
+ case_no: 2,
373
+ case_title: 'with additional case',
374
+ month: '201410',
375
+ count: 4,
376
+ additional: 'hoge',
377
+ expected: %w(201410_hoge 201411_hoge 201412_hoge 201501_hoge)
378
+ }
379
+ ]
380
+
381
+ cases.each do |c|
382
+ it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
383
+ begin
384
+ case_before c
385
+
386
+ # -- given --
387
+ defoker_core = Defoker::Core.new
388
+
389
+ # -- when --
390
+ actual = defoker_core.months(c[:month], count: c[:count], additional: c[:additional])
391
+
392
+ # -- then --
393
+ expect(actual).to eq(c[:expected])
394
+ ensure
395
+ case_after c
396
+ end
397
+ end
398
+
399
+ def case_before(c)
400
+ # implement each case before
401
+ end
402
+
403
+ def case_after(c)
404
+ # implement each case after
405
+ end
406
+ end
407
+ end
408
+
409
+ context :this_year do
410
+ cases = [
411
+ {
412
+ case_no: 1,
413
+ case_title: 'no additional case',
414
+ dummy_year: 2014,
415
+ dummy_month: 9,
416
+ dummy_day: 1,
417
+ additional: '',
418
+ expected: '2014'
419
+ },
420
+ {
421
+ case_no: 2,
422
+ case_title: 'with additional case',
423
+ dummy_year: 2014,
424
+ dummy_month: 9,
425
+ dummy_day: 1,
426
+ additional: 'hoge',
427
+ expected: '2014_hoge'
428
+ }
429
+ ]
430
+
431
+ cases.each do |c|
432
+ it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
433
+ begin
434
+ case_before c
435
+
436
+ # -- given --
437
+ defoker_core = Defoker::Core.new
438
+ Timecop.freeze(Time.local(c[:dummy_year], c[:dummy_month], c[:dummy_day]))
439
+
440
+ # -- when --
441
+ actual = defoker_core.this_year(additional: c[:additional])
442
+
443
+ # -- then --
444
+ expect(actual).to eq(c[:expected])
445
+ ensure
446
+ case_after c
447
+ end
448
+ end
449
+
450
+ def case_before(c)
451
+ # implement each case before
452
+ end
453
+
454
+ def case_after(c)
455
+ # implement each case after
456
+ end
457
+ end
458
+ end
459
+
460
+ context :next_year do
461
+ cases = [
462
+ {
463
+ case_no: 1,
464
+ case_title: 'no additional case',
465
+ dummy_year: 2014,
466
+ dummy_month: 9,
467
+ dummy_day: 1,
468
+ additional: '',
469
+ expected: '2015'
470
+ },
471
+ {
472
+ case_no: 2,
473
+ case_title: 'with additional case',
474
+ dummy_year: 2014,
475
+ dummy_month: 9,
476
+ dummy_day: 1,
477
+ additional: 'hoge',
478
+ expected: '2015_hoge'
479
+ }
480
+ ]
481
+
482
+ cases.each do |c|
483
+ it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
484
+ begin
485
+ case_before c
486
+
487
+ # -- given --
488
+ defoker_core = Defoker::Core.new
489
+ Timecop.freeze(Time.local(c[:dummy_year], c[:dummy_month], c[:dummy_day]))
490
+
491
+ # -- when --
492
+ actual = defoker_core.next_year(additional: c[:additional])
493
+
494
+ # -- then --
495
+ expect(actual).to eq(c[:expected])
496
+ ensure
497
+ case_after c
498
+ end
499
+ end
500
+
501
+ def case_before(c)
502
+ # implement each case before
503
+ end
504
+
505
+ def case_after(c)
506
+ # implement each case after
507
+ end
508
+ end
509
+ end
510
+
511
+ context :previous_year do
512
+ cases = [
513
+ {
514
+ case_no: 1,
515
+ case_title: 'no additional case',
516
+ dummy_year: 2014,
517
+ dummy_month: 9,
518
+ dummy_day: 1,
519
+ additional: '',
520
+ expected: '2013'
521
+ },
522
+ {
523
+ case_no: 2,
524
+ case_title: 'with additional case',
525
+ dummy_year: 2014,
526
+ dummy_month: 9,
527
+ dummy_day: 1,
528
+ additional: 'hoge',
529
+ expected: '2013_hoge'
530
+ }
531
+ ]
532
+
533
+ cases.each do |c|
534
+ it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
535
+ begin
536
+ case_before c
537
+
538
+ # -- given --
539
+ defoker_core = Defoker::Core.new
540
+ Timecop.freeze(Time.local(c[:dummy_year], c[:dummy_month], c[:dummy_day]))
541
+
542
+ # -- when --
543
+ actual = defoker_core.previous_year(additional: c[:additional])
544
+
545
+ # -- then --
546
+ expect(actual).to eq(c[:expected])
547
+ ensure
548
+ case_after c
549
+ end
550
+ end
551
+
552
+ def case_before(c)
553
+ # implement each case before
554
+ end
555
+
556
+ def case_after(c)
557
+ # implement each case after
558
+ end
559
+ end
560
+ end
561
+
562
+ context :years do
563
+ cases = [
564
+ {
565
+ case_no: 1,
566
+ case_title: 'no additional case',
567
+ year: '2014',
568
+ count: 4,
569
+ additional: '',
570
+ expected: %w(2014 2015 2016 2017)
571
+ },
572
+ {
573
+ case_no: 2,
574
+ case_title: 'with additional case',
575
+ year: '2014',
576
+ count: 4,
577
+ additional: 'hoge',
578
+ expected: %w(2014_hoge 2015_hoge 2016_hoge 2017_hoge)
579
+ }
580
+ ]
581
+
582
+ cases.each do |c|
583
+ it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
584
+ begin
585
+ case_before c
586
+
587
+ # -- given --
588
+ defoker_core = Defoker::Core.new
589
+
590
+ # -- when --
591
+ actual = defoker_core.years(c[:year], count: c[:count], additional: c[:additional])
592
+
593
+ # -- then --
594
+ expect(actual).to eq(c[:expected])
595
+ ensure
596
+ case_after c
597
+ end
598
+ end
599
+
600
+ def case_before(c)
601
+ # implement each case before
602
+ end
603
+
604
+ def case_after(c)
605
+ # implement each case after
606
+ end
607
+ end
608
+ end
609
+ end