tudu 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,762 +1,799 @@
1
- # encoding: utf-8
2
- require "spec_helper"
3
- require "tudu_core"
4
- require "tasks"
5
-
6
- describe Tudu::Tasks do
7
-
8
- context :todo? do
9
- cases = [
10
- {
11
- case_no: 1,
12
- case_title: "todo task",
13
- name: "task_name",
14
- type: "todos",
15
- expected: true,
16
- },
17
- {
18
- case_no: 2,
19
- case_title: "not todo task",
20
- name: "task_name",
21
- type: "doings",
22
- expected: false,
23
- },
24
- ]
25
-
26
- cases.each do |c|
27
- it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
28
- begin
29
- case_before c
30
-
31
- # -- given --
32
- tudu_task = Tudu::Tasks.new(c[:type], c[:name])
33
-
34
- # -- when --
35
- actual = tudu_task.todo?
36
-
37
- # -- then --
38
- ret = expect(actual).to eq(c[:expected])
39
- ensure
40
- case_after c
41
- end
42
- end
43
-
44
- def case_before(c)
45
- # implement each case before
46
-
47
- end
48
-
49
- def case_after(c)
50
- # implement each case after
51
- end
52
- end
53
- end
54
-
55
- context :doing? do
56
- cases = [
57
- {
58
- case_no: 1,
59
- case_title: "doing task",
60
- name: "task_name",
61
- type: "doings",
62
- expected: true,
63
- },
64
- {
65
- case_no: 2,
66
- case_title: "not doing task",
67
- name: "task_name",
68
- type: "todos",
69
- expected: false,
70
- },
71
- ]
72
-
73
- cases.each do |c|
74
- it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
75
- begin
76
- case_before c
77
-
78
- # -- given --
79
- tudu_task = Tudu::Tasks.new(c[:type], c[:name])
80
-
81
- # -- when --
82
- actual = tudu_task.doing?
83
-
84
- # -- then --
85
- ret = expect(actual).to eq(c[:expected])
86
- ensure
87
- case_after c
88
-
89
- end
90
- end
91
-
92
- def case_before(c)
93
- # implement each case before
94
-
95
- end
96
-
97
- def case_after(c)
98
- # implement each case after
99
- end
100
- end
101
- end
102
-
103
- context :done? do
104
- cases = [
105
- {
106
- case_no: 1,
107
- case_title: "done task",
108
- name: "task_name",
109
- type: "dones",
110
- expected: true,
111
- },
112
- {
113
- case_no: 2,
114
- case_title: "not done task",
115
- name: "task_name",
116
- type: "doings",
117
- expected: false,
118
- },
119
- ]
120
-
121
- cases.each do |c|
122
- it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
123
- begin
124
- case_before c
125
-
126
- # -- given --
127
- tudu_task = Tudu::Tasks.new(c[:type], c[:name])
128
-
129
- # -- when --
130
- actual = tudu_task.done?
131
-
132
- # -- then --
133
- ret = expect(actual).to eq(c[:expected])
134
- ensure
135
- case_after c
136
- end
137
- end
138
-
139
- def case_before(c)
140
- # implement each case before
141
-
142
- end
143
-
144
- def case_after(c)
145
- # implement each case after
146
- end
147
- end
148
- end
149
-
150
-
151
- context :get_tasks_from_file do
152
- cases = [
153
- {
154
- case_no: 1,
155
- case_title: "get todos from file",
156
- type: "todos",
157
- texts: ["task1", "task2", "task3"],
158
- expected: ["task1", "task2", "task3"],
159
- },
160
- {
161
- case_no: 2,
162
- case_title: "get doings from file",
163
- type: "doings",
164
- texts: ["task1", "task2", "task3"],
165
- expected: ["task1", "task2", "task3"],
166
- },
167
- {
168
- case_no: 3,
169
- case_title: "get done from file",
170
- type: "dones",
171
- texts: ["task1", "task2", "task3"],
172
- expected: ["task1", "task2", "task3"],
173
- },
174
- ]
175
-
176
- cases.each do |c|
177
- it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
178
- begin
179
- case_before c
180
-
181
- # -- given --
182
- # nothing
183
-
184
- # -- when --
185
- actual = Tudu::Tasks.get_tasks_from_file(c[:type])
186
-
187
- # -- then --
188
- ret = expect(actual).to eq(c[:expected])
189
- ensure
190
- case_after c
191
- end
192
- end
193
-
194
- def case_before(c)
195
- # implement each case before
196
- Dir.mkdir("./#{Tudu::Tasks::TUDU_DIR}")
197
- File.open("./#{Tudu::Tasks::TUDU_DIR}/#{c[:type]}", "w") {|f|f.puts c[:texts].join("\n")}
198
- end
199
-
200
- def case_after(c)
201
- # implement each case after
202
- return unless File.exists? Tudu::Tasks::TUDU_DIR
203
- FileUtils.rm_rf(Tudu::Tasks::TUDU_DIR)
204
- end
205
- end
206
- end
207
-
208
- context :get_tasks do
209
- cases = [
210
- {
211
- case_no: 1,
212
- case_title: "get todos from file",
213
- type: "todos",
214
- texts: ["task1", "task2", "task3"],
215
- expected: [
216
- Tudu::Tasks.new("todos", "task1"),
217
- Tudu::Tasks.new("todos", "task2"),
218
- Tudu::Tasks.new("todos", "task3"),
219
- ],
220
- },
221
- {
222
- case_no: 2,
223
- case_title: "get doings from file",
224
- type: "doings",
225
- texts: ["task1", "task2", "task3"],
226
- expected: [
227
- Tudu::Tasks.new("doings", "task1"),
228
- Tudu::Tasks.new("doings", "task2"),
229
- Tudu::Tasks.new("doings", "task3"),
230
- ],
231
- },
232
- {
233
- case_no: 3,
234
- case_title: "get done from file",
235
- type: "dones",
236
- texts: ["task1", "task2", "task3"],
237
- expected: [
238
- Tudu::Tasks.new("dones", "task1"),
239
- Tudu::Tasks.new("dones", "task2"),
240
- Tudu::Tasks.new("dones", "task3"),
241
- ],
242
- },
243
- ]
244
-
245
- cases.each do |c|
246
- it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
247
- begin
248
- case_before c
249
-
250
- # -- given --
251
- # nothing
252
-
253
- # -- when --
254
- actual = Tudu::Tasks.get_tasks(c[:type])
255
-
256
- # -- then --
257
- ret = expect(actual).to eq(c[:expected])
258
- ensure
259
- case_after c
260
- end
261
- end
262
-
263
- def case_before(c)
264
- # implement each case before
265
- Dir.mkdir("./#{Tudu::Tasks::TUDU_DIR}")
266
- File.open("./#{Tudu::Tasks::TUDU_DIR}/#{c[:type]}", "w") {|f|f.puts c[:texts].join("\n")}
267
- end
268
-
269
- def case_after(c)
270
- # implement each case after
271
- return unless File.exists? Tudu::Tasks::TUDU_DIR
272
- FileUtils.rm_rf(Tudu::Tasks::TUDU_DIR)
273
- end
274
- end
275
- end
276
-
277
- context :get_todos do
278
- cases = [
279
- {
280
- case_no: 1,
281
- case_title: "get doings from file",
282
- type: "doings",
283
- texts: ["task1", "task2", "task3"],
284
- expected: [
285
- Tudu::Tasks.new("doings", "task1"),
286
- Tudu::Tasks.new("doings", "task2"),
287
- Tudu::Tasks.new("doings", "task3"),
288
- ],
289
- },
290
- ]
291
-
292
- cases.each do |c|
293
- it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
294
- begin
295
- case_before c
296
-
297
- # -- given --
298
- # nothing
299
-
300
- # -- when --
301
- actual = Tudu::Tasks.get_doings
302
-
303
- # -- then --
304
- ret = expect(actual).to eq(c[:expected])
305
- ensure
306
- case_after c
307
- end
308
- end
309
-
310
- def case_before(c)
311
- # implement each case before
312
- Dir.mkdir("./#{Tudu::Tasks::TUDU_DIR}")
313
- File.open("./#{Tudu::Tasks::TUDU_DIR}/#{c[:type]}", "w") {|f|f.puts c[:texts].join("\n")}
314
- end
315
-
316
- def case_after(c)
317
- # implement each case after
318
- return unless File.exists? Tudu::Tasks::TUDU_DIR
319
- FileUtils.rm_rf(Tudu::Tasks::TUDU_DIR)
320
- end
321
- end
322
- end
323
-
324
- context :get_dones do
325
- cases = [
326
- {
327
- case_no: 1,
328
- case_title: "get done from file",
329
- type: "dones",
330
- texts: ["task1", "task2", "task3"],
331
- expected: [
332
- Tudu::Tasks.new("dones", "task1"),
333
- Tudu::Tasks.new("dones", "task2"),
334
- Tudu::Tasks.new("dones", "task3"),
335
- ],
336
- },
337
- ]
338
-
339
- cases.each do |c|
340
- it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
341
- begin
342
- case_before c
343
-
344
- # -- given --
345
- # nothing
346
-
347
- # -- when --
348
- actual = Tudu::Tasks.get_dones
349
-
350
- # -- then --
351
- ret = expect(actual).to eq(c[:expected])
352
- ensure
353
- case_after c
354
- end
355
- end
356
-
357
- def case_before(c)
358
- # implement each case before
359
- Dir.mkdir("./#{Tudu::Tasks::TUDU_DIR}")
360
- File.open("./#{Tudu::Tasks::TUDU_DIR}/#{c[:type]}", "w") {|f|f.puts c[:texts].join("\n")}
361
- end
362
-
363
- def case_after(c)
364
- # implement each case after
365
- return unless File.exists? Tudu::Tasks::TUDU_DIR
366
- FileUtils.rm_rf(Tudu::Tasks::TUDU_DIR)
367
- end
368
- end
369
- end
370
-
371
- context :find_tasks do
372
- cases = [
373
- {
374
- case_no: 1,
375
- case_title: "find todos from tasks",
376
- type: "todos",
377
- texts: ["task1", "task2", "task3"],
378
- search_name: "task1",
379
- expected: Tudu::Tasks.new("todos", "task1")
380
- },
381
- {
382
- case_no: 2,
383
- case_title: "find doings from tasks",
384
- type: "doings",
385
- texts: ["task1", "task2", "task3"],
386
- search_name: "task1",
387
- expected: Tudu::Tasks.new("doings", "task1")
388
- },
389
- {
390
- case_no: 3,
391
- case_title: "find done from tasks",
392
- type: "dones",
393
- texts: ["task1", "task2", "task3"],
394
- search_name: "task1",
395
- expected: Tudu::Tasks.new("dones", "task1")
396
- },
397
- {
398
- case_no: 4,
399
- case_title: "not find",
400
- type: "dones",
401
- texts: ["task1", "task2", "task3"],
402
- search_name: "task4",
403
- expected: nil
404
- },
405
- ]
406
-
407
- cases.each do |c|
408
- it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
409
- begin
410
- case_before c
411
-
412
- # -- given --
413
- # nothing
414
-
415
- # -- when --
416
- actual = Tudu::Tasks.find_tasks c[:search_name]
417
-
418
- # -- then --
419
- ret = expect(actual).to eq(c[:expected])
420
- ensure
421
- case_after c
422
- end
423
- end
424
-
425
- def case_before(c)
426
- # implement each case before
427
- Tudu::Core.new.init
428
- Dir.mkdir(Tudu::Tasks::TUDU_DIR) unless File.exists?(Tudu::Tasks::TUDU_DIR)
429
- File.open("./#{Tudu::Tasks::TUDU_DIR}/#{c[:type]}", "w") {|f|f.puts c[:texts].join("\n")}
430
- end
431
-
432
- def case_after(c)
433
- # implement each case after
434
- return unless File.exists? Tudu::Tasks::TUDU_DIR
435
- FileUtils.rm_rf(Tudu::Tasks::TUDU_DIR)
436
- end
437
- end
438
- end
439
-
440
- context :choose do
441
- cases = [
442
- {
443
- case_no: 1,
444
- case_title: "choose task",
445
- type: "todos",
446
- texts: ["task1", "task2", "task3"],
447
- choose: "task1",
448
- expected: [
449
- Tudu::Tasks.new("todos", "task2"),
450
- Tudu::Tasks.new("todos", "task3"),
451
- Tudu::Tasks.new("doings", "task1"),
452
- ]
453
- },
454
- {
455
- case_no: 2,
456
- case_title: "aleady exists doing",
457
- type: "doings",
458
- texts: ["task1", "task2", "task3"],
459
- choose: "task1",
460
- expected: [
461
- Tudu::Tasks.new("doings", "task1"),
462
- Tudu::Tasks.new("doings", "task2"),
463
- Tudu::Tasks.new("doings", "task3"),
464
- ]
465
- },
466
- {
467
- case_no: 3,
468
- case_title: "not exists task",
469
- type: "todos",
470
- texts: ["task1", "task2", "task3"],
471
- choose: "task4",
472
- expected: [
473
- Tudu::Tasks.new("todos", "task1"),
474
- Tudu::Tasks.new("todos", "task2"),
475
- Tudu::Tasks.new("todos", "task3"),
476
- ]
477
- },
478
- {
479
- case_no: 4,
480
- case_title: "task exists, but dones",
481
- type: "dones",
482
- texts: ["task1", "task2", "task3"],
483
- choose: "task1",
484
- expected: [
485
- Tudu::Tasks.new("dones", "task1"),
486
- Tudu::Tasks.new("dones", "task2"),
487
- Tudu::Tasks.new("dones", "task3"),
488
- ]
489
- },
490
- ]
491
-
492
- cases.each do |c|
493
- it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
494
- begin
495
- case_before c
496
-
497
- # -- given --
498
- # nothing
499
-
500
- # -- when --
501
- Tudu::Tasks.choose c[:choose]
502
-
503
- # -- then --
504
- expect(Tudu::Tasks.get_tasks).to eq(c[:expected])
505
- ensure
506
- case_after c
507
- end
508
- end
509
-
510
- def case_before(c)
511
- # implement each case before
512
- Tudu::Core.new.init
513
- File.open("./#{Tudu::Tasks::TUDU_DIR}/#{c[:type]}", "w") {|f|f.puts c[:texts].join("\n")}
514
- end
515
-
516
- def case_after(c)
517
- # implement each case after
518
- return unless File.exists? Tudu::Tasks::TUDU_DIR
519
- FileUtils.rm_rf(Tudu::Tasks::TUDU_DIR)
520
- end
521
- end
522
- end
523
-
524
- context :done do
525
- cases = [
526
- {
527
- case_no: 1,
528
- case_title: "one doing to done, shift todo to doing",
529
- task_names: ["task1", "task2", "task3"],
530
- choose: "task1",
531
- expected: [
532
- Tudu::Tasks.new("todos", "task3"),
533
- Tudu::Tasks.new("doings", "task2"),
534
- Tudu::Tasks.new("dones", "task1"),
535
- ]
536
- },
537
- {
538
- case_no: 2,
539
- case_title: "one doing to done, not shift todo to doing",
540
- task_names: ["task1"],
541
- choose: "task1",
542
- expected: [
543
- Tudu::Tasks.new("dones", "task1"),
544
- ]
545
- },
546
- {
547
- case_no: 3,
548
- case_title: "no doing",
549
- task_names: ["task1"],
550
- choose: "",
551
- expected: [
552
- Tudu::Tasks.new("todos", "task1"),
553
- ]
554
- },
555
- ]
556
-
557
- cases.each do |c|
558
- it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
559
- begin
560
- case_before c
561
-
562
- # -- given --
563
- Tudu::Core.new.init
564
- Tudu::Tasks.add *c[:task_names]
565
- Tudu::Tasks.choose c[:choose]
566
-
567
- # -- when --
568
- Tudu::Tasks.done
569
-
570
- # -- then --
571
- expect(Tudu::Tasks.get_tasks).to eq(c[:expected])
572
- ensure
573
- case_after c
574
- end
575
- end
576
-
577
- def case_before(c)
578
- # implement each case before
579
- end
580
-
581
- def case_after(c)
582
- # implement each case after
583
- return unless File.exists? Tudu::Tasks::TUDU_DIR
584
- FileUtils.rm_rf(Tudu::Tasks::TUDU_DIR)
585
- end
586
- end
587
- end
588
-
589
- context :add do
590
- cases = [
591
- {
592
- case_no: 1,
593
- case_title: "single add",
594
- task_names1: "task_name",
595
- task_names2: nil,
596
- task_names3: nil,
597
- expected: [
598
- Tudu::Tasks.new("todos", "task_name")
599
- ]
600
- },
601
- {
602
- case_no: 2,
603
- case_title: "nil add",
604
- task_names1: nil,
605
- task_names2: nil,
606
- task_names3: nil,
607
- expected: []
608
- },
609
- {
610
- case_no: 3,
611
- case_title: "multi add",
612
- task_names1: "task_name1",
613
- task_names2: "task_name2",
614
- task_names3: "task_name3",
615
- expected: [
616
- Tudu::Tasks.new("todos", "task_name1"),
617
- Tudu::Tasks.new("todos", "task_name2"),
618
- Tudu::Tasks.new("todos", "task_name3")
619
- ]
620
- },
621
- {
622
- case_no: 4,
623
- case_title: "duplicate add",
624
- task_names1: "task_name1",
625
- task_names2: "task_name1",
626
- task_names3: nil,
627
- expected: [
628
- Tudu::Tasks.new("todos", "task_name1"),
629
- ]
630
- },
631
- ]
632
-
633
- cases.each do |c|
634
- it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
635
- begin
636
- case_before c
637
-
638
- # -- given --
639
- Tudu::Core.new.init
640
-
641
- # -- when --
642
- actual = Tudu::Tasks.add c[:task_names1], c[:task_names2], c[:task_names3]
643
-
644
- # -- then --
645
- actual = Tudu::Tasks.get_todos
646
- expect(actual).to eq(c[:expected])
647
- ensure
648
- case_after c
649
- end
650
- end
651
-
652
- def case_before(c)
653
- # implement each case before
654
- end
655
-
656
- def case_after(c)
657
- return unless File.exists? Tudu::Tasks::TUDU_DIR
658
- FileUtils.rm_rf(Tudu::Tasks::TUDU_DIR)
659
- end
660
- end
661
- end
662
-
663
-
664
- context :remove do
665
- cases = [
666
- {
667
- case_no: 1,
668
- case_title: "single remove",
669
- add_tasks: ["task_name"],
670
- remove_tasks: ["task_name"],
671
- expected_tasks: [],
672
- },
673
- {
674
- case_no: 2,
675
- case_title: "multi remove",
676
- add_tasks: ["task_name1", "task_name2", "task_name3"],
677
- remove_tasks: ["task_name1", "task_name2", "task_name3"],
678
- expected_tasks: [],
679
- },
680
- {
681
- case_no: 3,
682
- case_title: "not remove",
683
- add_tasks: ["task_name"],
684
- remove_tasks: ["invalid name"],
685
- expected_tasks: [Tudu::Tasks.new("todos", "task_name")],
686
- },
687
- ]
688
-
689
- cases.each do |c|
690
- it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
691
- begin
692
- case_before c
693
-
694
- # -- given --
695
- Tudu::Core.new.init
696
- Tudu::Tasks.add *c[:add_tasks]
697
-
698
- # -- when --
699
- Tudu::Tasks.remove *c[:remove_tasks]
700
-
701
- # -- then --
702
- actual = Tudu::Tasks.get_tasks
703
- expect(actual).to eq(c[:expected_tasks])
704
- ensure
705
- case_after c
706
- end
707
- end
708
-
709
- def case_before(c)
710
- # implement each case before
711
- end
712
-
713
- def case_after(c)
714
- return unless File.exists? Tudu::Tasks::TUDU_DIR
715
- FileUtils.rm_rf(Tudu::Tasks::TUDU_DIR)
716
- end
717
- end
718
- end
719
-
720
- context :filter_tasks do
721
- cases = [
722
- {
723
- case_no: 1,
724
- case_title: "get todos from file",
725
- tasks: [
726
- Tudu::Tasks.new("doings", "task1_1"),
727
- Tudu::Tasks.new("doings", "task1_2"),
728
- Tudu::Tasks.new("doings", "task3"),
729
- ],
730
- filter_word: "task1_1",
731
- expected: [Tudu::Tasks.new("doings", "task1_1")],
732
- },
733
- ]
734
-
735
- cases.each do |c|
736
- it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
737
- begin
738
- case_before c
739
-
740
- # -- given --
741
- # nothing
742
-
743
- # -- when --
744
- actual = Tudu::Tasks.filter_tasks(c[:tasks], c[:filter_word])
745
-
746
- # -- then --
747
- ret = expect(actual).to eq(c[:expected])
748
- ensure
749
- case_after c
750
- end
751
- end
752
-
753
- def case_before(c)
754
- # implement each case before
755
- end
756
-
757
- def case_after(c)
758
- # implement each case after
759
- end
760
- end
761
- end
762
- end
1
+ # encoding: utf-8
2
+ require "spec_helper"
3
+ require "tudu_core"
4
+ require "tasks"
5
+
6
+ describe Tudu::Tasks do
7
+
8
+ context :todo? do
9
+ cases = [
10
+ {
11
+ case_no: 1,
12
+ case_title: "todo task",
13
+ name: "task_name",
14
+ type: "todos",
15
+ expected: true,
16
+ },
17
+ {
18
+ case_no: 2,
19
+ case_title: "not todo task",
20
+ name: "task_name",
21
+ type: "doings",
22
+ expected: false,
23
+ },
24
+ ]
25
+
26
+ cases.each do |c|
27
+ it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
28
+ begin
29
+ case_before c
30
+
31
+ # -- given --
32
+ tudu_task = Tudu::Tasks.new(c[:type], c[:name])
33
+
34
+ # -- when --
35
+ actual = tudu_task.todo?
36
+
37
+ # -- then --
38
+ ret = expect(actual).to eq(c[:expected])
39
+ ensure
40
+ case_after c
41
+ end
42
+ end
43
+
44
+ def case_before(c)
45
+ # implement each case before
46
+
47
+ end
48
+
49
+ def case_after(c)
50
+ # implement each case after
51
+ end
52
+ end
53
+ end
54
+
55
+ context :doing? do
56
+ cases = [
57
+ {
58
+ case_no: 1,
59
+ case_title: "doing task",
60
+ name: "task_name",
61
+ type: "doings",
62
+ expected: true,
63
+ },
64
+ {
65
+ case_no: 2,
66
+ case_title: "not doing task",
67
+ name: "task_name",
68
+ type: "todos",
69
+ expected: false,
70
+ },
71
+ ]
72
+
73
+ cases.each do |c|
74
+ it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
75
+ begin
76
+ case_before c
77
+
78
+ # -- given --
79
+ tudu_task = Tudu::Tasks.new(c[:type], c[:name])
80
+
81
+ # -- when --
82
+ actual = tudu_task.doing?
83
+
84
+ # -- then --
85
+ ret = expect(actual).to eq(c[:expected])
86
+ ensure
87
+ case_after c
88
+
89
+ end
90
+ end
91
+
92
+ def case_before(c)
93
+ # implement each case before
94
+
95
+ end
96
+
97
+ def case_after(c)
98
+ # implement each case after
99
+ end
100
+ end
101
+ end
102
+
103
+ context :done? do
104
+ cases = [
105
+ {
106
+ case_no: 1,
107
+ case_title: "done task",
108
+ name: "task_name",
109
+ type: "dones",
110
+ expected: true,
111
+ },
112
+ {
113
+ case_no: 2,
114
+ case_title: "not done task",
115
+ name: "task_name",
116
+ type: "doings",
117
+ expected: false,
118
+ },
119
+ ]
120
+
121
+ cases.each do |c|
122
+ it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
123
+ begin
124
+ case_before c
125
+
126
+ # -- given --
127
+ tudu_task = Tudu::Tasks.new(c[:type], c[:name])
128
+
129
+ # -- when --
130
+ actual = tudu_task.done?
131
+
132
+ # -- then --
133
+ ret = expect(actual).to eq(c[:expected])
134
+ ensure
135
+ case_after c
136
+ end
137
+ end
138
+
139
+ def case_before(c)
140
+ # implement each case before
141
+
142
+ end
143
+
144
+ def case_after(c)
145
+ # implement each case after
146
+ end
147
+ end
148
+ end
149
+
150
+
151
+ context :get_tasks_from_file do
152
+ cases = [
153
+ {
154
+ case_no: 1,
155
+ case_title: "get todos from file",
156
+ type: "todos",
157
+ texts: ["task1", "task2", "task3"],
158
+ expected: ["task1", "task2", "task3"],
159
+ },
160
+ {
161
+ case_no: 2,
162
+ case_title: "get doings from file",
163
+ type: "doings",
164
+ texts: ["task1", "task2", "task3"],
165
+ expected: ["task1", "task2", "task3"],
166
+ },
167
+ {
168
+ case_no: 3,
169
+ case_title: "get done from file",
170
+ type: "dones",
171
+ texts: ["task1", "task2", "task3"],
172
+ expected: ["task1", "task2", "task3"],
173
+ },
174
+ ]
175
+
176
+ cases.each do |c|
177
+ it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
178
+ begin
179
+ case_before c
180
+
181
+ # -- given --
182
+ # nothing
183
+
184
+ # -- when --
185
+ actual = Tudu::Tasks.get_tasks_from_file(c[:type])
186
+
187
+ # -- then --
188
+ ret = expect(actual).to eq(c[:expected])
189
+ ensure
190
+ case_after c
191
+ end
192
+ end
193
+
194
+ def case_before(c)
195
+ # implement each case before
196
+ Dir.mkdir("./#{Tudu::Tasks::TUDU_DIR}")
197
+ File.open("./#{Tudu::Tasks::TUDU_DIR}/#{c[:type]}", "w") {|f|f.puts c[:texts].join("\n")}
198
+ end
199
+
200
+ def case_after(c)
201
+ # implement each case after
202
+ return unless File.exists? Tudu::Tasks::TUDU_DIR
203
+ FileUtils.rm_rf(Tudu::Tasks::TUDU_DIR)
204
+ end
205
+ end
206
+ end
207
+
208
+ context :get_tasks do
209
+ cases = [
210
+ {
211
+ case_no: 1,
212
+ case_title: "get todos from file",
213
+ type: "todos",
214
+ texts: ["task1", "task2", "task3"],
215
+ expected: [
216
+ Tudu::Tasks.new("todos", "task1"),
217
+ Tudu::Tasks.new("todos", "task2"),
218
+ Tudu::Tasks.new("todos", "task3"),
219
+ ],
220
+ },
221
+ {
222
+ case_no: 2,
223
+ case_title: "get doings from file",
224
+ type: "doings",
225
+ texts: ["task1", "task2", "task3"],
226
+ expected: [
227
+ Tudu::Tasks.new("doings", "task1"),
228
+ Tudu::Tasks.new("doings", "task2"),
229
+ Tudu::Tasks.new("doings", "task3"),
230
+ ],
231
+ },
232
+ {
233
+ case_no: 3,
234
+ case_title: "get done from file",
235
+ type: "dones",
236
+ texts: ["task1", "task2", "task3"],
237
+ expected: [
238
+ Tudu::Tasks.new("dones", "task1"),
239
+ Tudu::Tasks.new("dones", "task2"),
240
+ Tudu::Tasks.new("dones", "task3"),
241
+ ],
242
+ },
243
+ ]
244
+
245
+ cases.each do |c|
246
+ it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
247
+ begin
248
+ case_before c
249
+
250
+ # -- given --
251
+ # nothing
252
+
253
+ # -- when --
254
+ actual = Tudu::Tasks.get_tasks(c[:type])
255
+
256
+ # -- then --
257
+ ret = expect(actual).to eq(c[:expected])
258
+ ensure
259
+ case_after c
260
+ end
261
+ end
262
+
263
+ def case_before(c)
264
+ # implement each case before
265
+ Dir.mkdir("./#{Tudu::Tasks::TUDU_DIR}")
266
+ File.open("./#{Tudu::Tasks::TUDU_DIR}/#{c[:type]}", "w") {|f|f.puts c[:texts].join("\n")}
267
+ end
268
+
269
+ def case_after(c)
270
+ # implement each case after
271
+ return unless File.exists? Tudu::Tasks::TUDU_DIR
272
+ FileUtils.rm_rf(Tudu::Tasks::TUDU_DIR)
273
+ end
274
+ end
275
+ end
276
+
277
+ context :get_todos do
278
+ cases = [
279
+ {
280
+ case_no: 1,
281
+ case_title: "get doings from file",
282
+ type: "doings",
283
+ texts: ["task1", "task2", "task3"],
284
+ expected: [
285
+ Tudu::Tasks.new("doings", "task1"),
286
+ Tudu::Tasks.new("doings", "task2"),
287
+ Tudu::Tasks.new("doings", "task3"),
288
+ ],
289
+ },
290
+ ]
291
+
292
+ cases.each do |c|
293
+ it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
294
+ begin
295
+ case_before c
296
+
297
+ # -- given --
298
+ # nothing
299
+
300
+ # -- when --
301
+ actual = Tudu::Tasks.get_doings
302
+
303
+ # -- then --
304
+ ret = expect(actual).to eq(c[:expected])
305
+ ensure
306
+ case_after c
307
+ end
308
+ end
309
+
310
+ def case_before(c)
311
+ # implement each case before
312
+ Dir.mkdir("./#{Tudu::Tasks::TUDU_DIR}")
313
+ File.open("./#{Tudu::Tasks::TUDU_DIR}/#{c[:type]}", "w") {|f|f.puts c[:texts].join("\n")}
314
+ end
315
+
316
+ def case_after(c)
317
+ # implement each case after
318
+ return unless File.exists? Tudu::Tasks::TUDU_DIR
319
+ FileUtils.rm_rf(Tudu::Tasks::TUDU_DIR)
320
+ end
321
+ end
322
+ end
323
+
324
+ context :get_dones do
325
+ cases = [
326
+ {
327
+ case_no: 1,
328
+ case_title: "get done from file",
329
+ type: "dones",
330
+ texts: ["task1", "task2", "task3"],
331
+ expected: [
332
+ Tudu::Tasks.new("dones", "task1"),
333
+ Tudu::Tasks.new("dones", "task2"),
334
+ Tudu::Tasks.new("dones", "task3"),
335
+ ],
336
+ },
337
+ ]
338
+
339
+ cases.each do |c|
340
+ it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
341
+ begin
342
+ case_before c
343
+
344
+ # -- given --
345
+ # nothing
346
+
347
+ # -- when --
348
+ actual = Tudu::Tasks.get_dones
349
+
350
+ # -- then --
351
+ ret = expect(actual).to eq(c[:expected])
352
+ ensure
353
+ case_after c
354
+ end
355
+ end
356
+
357
+ def case_before(c)
358
+ # implement each case before
359
+ Dir.mkdir("./#{Tudu::Tasks::TUDU_DIR}")
360
+ File.open("./#{Tudu::Tasks::TUDU_DIR}/#{c[:type]}", "w") {|f|f.puts c[:texts].join("\n")}
361
+ end
362
+
363
+ def case_after(c)
364
+ # implement each case after
365
+ return unless File.exists? Tudu::Tasks::TUDU_DIR
366
+ FileUtils.rm_rf(Tudu::Tasks::TUDU_DIR)
367
+ end
368
+ end
369
+ end
370
+
371
+ context :find_tasks do
372
+ cases = [
373
+ {
374
+ case_no: 1,
375
+ case_title: "find todos from tasks",
376
+ type: "todos",
377
+ texts: ["task1", "task2", "task3"],
378
+ search_name: "task1",
379
+ expected: Tudu::Tasks.new("todos", "task1")
380
+ },
381
+ {
382
+ case_no: 2,
383
+ case_title: "find doings from tasks",
384
+ type: "doings",
385
+ texts: ["task1", "task2", "task3"],
386
+ search_name: "task1",
387
+ expected: Tudu::Tasks.new("doings", "task1")
388
+ },
389
+ {
390
+ case_no: 3,
391
+ case_title: "find done from tasks",
392
+ type: "dones",
393
+ texts: ["task1", "task2", "task3"],
394
+ search_name: "task1",
395
+ expected: Tudu::Tasks.new("dones", "task1")
396
+ },
397
+ {
398
+ case_no: 4,
399
+ case_title: "not find",
400
+ type: "dones",
401
+ texts: ["task1", "task2", "task3"],
402
+ search_name: "task4",
403
+ expected: nil
404
+ },
405
+ ]
406
+
407
+ cases.each do |c|
408
+ it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
409
+ begin
410
+ case_before c
411
+
412
+ # -- given --
413
+ # nothing
414
+
415
+ # -- when --
416
+ actual = Tudu::Tasks.find_tasks c[:search_name]
417
+
418
+ # -- then --
419
+ ret = expect(actual).to eq(c[:expected])
420
+ ensure
421
+ case_after c
422
+ end
423
+ end
424
+
425
+ def case_before(c)
426
+ # implement each case before
427
+ Tudu::Core.new.init
428
+ Dir.mkdir(Tudu::Tasks::TUDU_DIR) unless File.exists?(Tudu::Tasks::TUDU_DIR)
429
+ File.open("./#{Tudu::Tasks::TUDU_DIR}/#{c[:type]}", "w") {|f|f.puts c[:texts].join("\n")}
430
+ end
431
+
432
+ def case_after(c)
433
+ # implement each case after
434
+ return unless File.exists? Tudu::Tasks::TUDU_DIR
435
+ FileUtils.rm_rf(Tudu::Tasks::TUDU_DIR)
436
+ end
437
+ end
438
+ end
439
+
440
+ context :choose do
441
+ cases = [
442
+ {
443
+ case_no: 1,
444
+ case_title: "choose task",
445
+ type: "todos",
446
+ texts: ["task1", "task2", "task3"],
447
+ choose: "task1",
448
+ expected: [
449
+ Tudu::Tasks.new("todos", "task2"),
450
+ Tudu::Tasks.new("todos", "task3"),
451
+ Tudu::Tasks.new("doings", "task1"),
452
+ ]
453
+ },
454
+ {
455
+ case_no: 2,
456
+ case_title: "aleady exists doing",
457
+ type: "doings",
458
+ texts: ["task1", "task2", "task3"],
459
+ choose: "task1",
460
+ expected: [
461
+ Tudu::Tasks.new("doings", "task1"),
462
+ Tudu::Tasks.new("doings", "task2"),
463
+ Tudu::Tasks.new("doings", "task3"),
464
+ ]
465
+ },
466
+ {
467
+ case_no: 3,
468
+ case_title: "not exists task",
469
+ type: "todos",
470
+ texts: ["task1", "task2", "task3"],
471
+ choose: "task4",
472
+ expected: [
473
+ Tudu::Tasks.new("todos", "task1"),
474
+ Tudu::Tasks.new("todos", "task2"),
475
+ Tudu::Tasks.new("todos", "task3"),
476
+ ]
477
+ },
478
+ {
479
+ case_no: 4,
480
+ case_title: "task exists, but dones",
481
+ type: "dones",
482
+ texts: ["task1", "task2", "task3"],
483
+ choose: "task1",
484
+ expected: [
485
+ Tudu::Tasks.new("dones", "task1"),
486
+ Tudu::Tasks.new("dones", "task2"),
487
+ Tudu::Tasks.new("dones", "task3"),
488
+ ]
489
+ },
490
+ {
491
+ case_no: 5,
492
+ case_title: "task exists, empty args",
493
+ type: "todos",
494
+ texts: ["task1", "task2", "task3"],
495
+ choose: "",
496
+ expected: [
497
+ Tudu::Tasks.new("todos", "task2"),
498
+ Tudu::Tasks.new("todos", "task3"),
499
+ Tudu::Tasks.new("doings", "task1"),
500
+ ]
501
+ },
502
+ {
503
+ case_no: 6,
504
+ case_title: "task exists, nil args",
505
+ type: "todos",
506
+ texts: ["task1", "task2", "task3"],
507
+ choose: nil,
508
+ expected: [
509
+ Tudu::Tasks.new("todos", "task2"),
510
+ Tudu::Tasks.new("todos", "task3"),
511
+ Tudu::Tasks.new("doings", "task1"),
512
+ ]
513
+ },
514
+ {
515
+ case_no: 7,
516
+ case_title: "todos not exists, empty args",
517
+ type: "doings",
518
+ texts: ["task1", "task2", "task3"],
519
+ choose: nil,
520
+ expected: [
521
+ Tudu::Tasks.new("doings", "task1"),
522
+ Tudu::Tasks.new("doings", "task2"),
523
+ Tudu::Tasks.new("doings", "task3"),
524
+ ]
525
+ },
526
+
527
+ ]
528
+
529
+ cases.each do |c|
530
+ it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
531
+ begin
532
+ case_before c
533
+
534
+ # -- given --
535
+ # nothing
536
+
537
+ # -- when --
538
+ Tudu::Tasks.choose c[:choose]
539
+
540
+ # -- then --
541
+ expect(Tudu::Tasks.get_tasks).to eq(c[:expected])
542
+ ensure
543
+ case_after c
544
+ end
545
+ end
546
+
547
+ def case_before(c)
548
+ # implement each case before
549
+ Tudu::Core.new.init
550
+ File.open("./#{Tudu::Tasks::TUDU_DIR}/#{c[:type]}", "w") {|f|f.puts c[:texts].join("\n")}
551
+ end
552
+
553
+ def case_after(c)
554
+ # implement each case after
555
+ return unless File.exists? Tudu::Tasks::TUDU_DIR
556
+ FileUtils.rm_rf(Tudu::Tasks::TUDU_DIR)
557
+ end
558
+ end
559
+ end
560
+
561
+ context :done do
562
+ cases = [
563
+ {
564
+ case_no: 1,
565
+ case_title: "one doing to done, shift todo to doing",
566
+ task_names: ["task1", "task2", "task3"],
567
+ choose: "task1",
568
+ expected: [
569
+ Tudu::Tasks.new("todos", "task3"),
570
+ Tudu::Tasks.new("doings", "task2"),
571
+ Tudu::Tasks.new("dones", "task1"),
572
+ ]
573
+ },
574
+ {
575
+ case_no: 2,
576
+ case_title: "one doing to done, not shift todo to doing",
577
+ task_names: ["task1"],
578
+ choose: "task1",
579
+ expected: [
580
+ Tudu::Tasks.new("dones", "task1"),
581
+ ]
582
+ },
583
+ {
584
+ case_no: 3,
585
+ case_title: "no doing",
586
+ task_names: ["task1"],
587
+ choose: "",
588
+ expected: [
589
+ Tudu::Tasks.new("todos", "task1"),
590
+ ]
591
+ },
592
+ ]
593
+
594
+ cases.each do |c|
595
+ it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
596
+ begin
597
+ case_before c
598
+
599
+ # -- given --
600
+ Tudu::Core.new.init
601
+ Tudu::Tasks.add *c[:task_names]
602
+ Tudu::Tasks.choose c[:choose] unless c[:choose].empty?
603
+
604
+ # -- when --
605
+ Tudu::Tasks.done
606
+
607
+ # -- then --
608
+ expect(Tudu::Tasks.get_tasks).to eq(c[:expected])
609
+ ensure
610
+ case_after c
611
+ end
612
+ end
613
+
614
+ def case_before(c)
615
+ # implement each case before
616
+ end
617
+
618
+ def case_after(c)
619
+ # implement each case after
620
+ return unless File.exists? Tudu::Tasks::TUDU_DIR
621
+ FileUtils.rm_rf(Tudu::Tasks::TUDU_DIR)
622
+ end
623
+ end
624
+ end
625
+
626
+ context :add do
627
+ cases = [
628
+ {
629
+ case_no: 1,
630
+ case_title: "single add",
631
+ task_names1: "task_name",
632
+ task_names2: nil,
633
+ task_names3: nil,
634
+ expected: [
635
+ Tudu::Tasks.new("todos", "task_name")
636
+ ]
637
+ },
638
+ {
639
+ case_no: 2,
640
+ case_title: "nil add",
641
+ task_names1: nil,
642
+ task_names2: nil,
643
+ task_names3: nil,
644
+ expected: []
645
+ },
646
+ {
647
+ case_no: 3,
648
+ case_title: "multi add",
649
+ task_names1: "task_name1",
650
+ task_names2: "task_name2",
651
+ task_names3: "task_name3",
652
+ expected: [
653
+ Tudu::Tasks.new("todos", "task_name1"),
654
+ Tudu::Tasks.new("todos", "task_name2"),
655
+ Tudu::Tasks.new("todos", "task_name3")
656
+ ]
657
+ },
658
+ {
659
+ case_no: 4,
660
+ case_title: "duplicate add",
661
+ task_names1: "task_name1",
662
+ task_names2: "task_name1",
663
+ task_names3: nil,
664
+ expected: [
665
+ Tudu::Tasks.new("todos", "task_name1"),
666
+ ]
667
+ },
668
+ ]
669
+
670
+ cases.each do |c|
671
+ it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
672
+ begin
673
+ case_before c
674
+
675
+ # -- given --
676
+ Tudu::Core.new.init
677
+
678
+ # -- when --
679
+ actual = Tudu::Tasks.add c[:task_names1], c[:task_names2], c[:task_names3]
680
+
681
+ # -- then --
682
+ actual = Tudu::Tasks.get_todos
683
+ expect(actual).to eq(c[:expected])
684
+ ensure
685
+ case_after c
686
+ end
687
+ end
688
+
689
+ def case_before(c)
690
+ # implement each case before
691
+ end
692
+
693
+ def case_after(c)
694
+ return unless File.exists? Tudu::Tasks::TUDU_DIR
695
+ FileUtils.rm_rf(Tudu::Tasks::TUDU_DIR)
696
+ end
697
+ end
698
+ end
699
+
700
+
701
+ context :remove do
702
+ cases = [
703
+ {
704
+ case_no: 1,
705
+ case_title: "single remove",
706
+ add_tasks: ["task_name"],
707
+ remove_tasks: ["task_name"],
708
+ expected_tasks: [],
709
+ },
710
+ {
711
+ case_no: 2,
712
+ case_title: "multi remove",
713
+ add_tasks: ["task_name1", "task_name2", "task_name3"],
714
+ remove_tasks: ["task_name1", "task_name2", "task_name3"],
715
+ expected_tasks: [],
716
+ },
717
+ {
718
+ case_no: 3,
719
+ case_title: "not remove",
720
+ add_tasks: ["task_name"],
721
+ remove_tasks: ["invalid name"],
722
+ expected_tasks: [Tudu::Tasks.new("todos", "task_name")],
723
+ },
724
+ ]
725
+
726
+ cases.each do |c|
727
+ it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
728
+ begin
729
+ case_before c
730
+
731
+ # -- given --
732
+ Tudu::Core.new.init
733
+ Tudu::Tasks.add *c[:add_tasks]
734
+
735
+ # -- when --
736
+ Tudu::Tasks.remove *c[:remove_tasks]
737
+
738
+ # -- then --
739
+ actual = Tudu::Tasks.get_tasks
740
+ expect(actual).to eq(c[:expected_tasks])
741
+ ensure
742
+ case_after c
743
+ end
744
+ end
745
+
746
+ def case_before(c)
747
+ # implement each case before
748
+ end
749
+
750
+ def case_after(c)
751
+ return unless File.exists? Tudu::Tasks::TUDU_DIR
752
+ FileUtils.rm_rf(Tudu::Tasks::TUDU_DIR)
753
+ end
754
+ end
755
+ end
756
+
757
+ context :filter_tasks do
758
+ cases = [
759
+ {
760
+ case_no: 1,
761
+ case_title: "get todos from file",
762
+ tasks: [
763
+ Tudu::Tasks.new("doings", "task1_1"),
764
+ Tudu::Tasks.new("doings", "task1_2"),
765
+ Tudu::Tasks.new("doings", "task3"),
766
+ ],
767
+ filter_word: "task1_1",
768
+ expected: [Tudu::Tasks.new("doings", "task1_1")],
769
+ },
770
+ ]
771
+
772
+ cases.each do |c|
773
+ it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
774
+ begin
775
+ case_before c
776
+
777
+ # -- given --
778
+ # nothing
779
+
780
+ # -- when --
781
+ actual = Tudu::Tasks.filter_tasks(c[:tasks], c[:filter_word])
782
+
783
+ # -- then --
784
+ ret = expect(actual).to eq(c[:expected])
785
+ ensure
786
+ case_after c
787
+ end
788
+ end
789
+
790
+ def case_before(c)
791
+ # implement each case before
792
+ end
793
+
794
+ def case_after(c)
795
+ # implement each case after
796
+ end
797
+ end
798
+ end
799
+ end