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,574 +1,569 @@
1
- # encoding: utf-8
2
- require "spec_helper"
3
- require "tudu_core"
4
-
5
- describe Tudu::Core do
6
- context :init do
7
- cases = [
8
- {
9
- case_no: 1,
10
- case_title: "valid case",
11
- expected_files: [
12
- Tudu::Tasks::TUDU_FILE,
13
- Tudu::Tasks::TUDU_TODOS_FILE,
14
- Tudu::Tasks::TUDU_DOINGS_FILE,
15
- Tudu::Tasks::TUDU_DONES_FILE
16
- ],
17
- expected_contents: [
18
- Tudu::Tasks::TUDU_FILE_TEMPLATE,
19
- Tudu::Tasks::TUDU_TODOS_FILE_TEMPLATE,
20
- Tudu::Tasks::TUDU_DOINGS_FILE_TEMPLATE,
21
- Tudu::Tasks::TUDU_DONES_FILE_TEMPLATE
22
- ],
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_core = Tudu::Core.new
33
-
34
- # -- when --
35
- tudu_core.init
36
-
37
- # -- then --
38
- c[:expected_files].each_with_index do |f, index|
39
- actual = File.open("./tudu/#{f}") {|f|f.read}
40
- expect(actual).to eq(c[:expected_contents][index])
41
- end
42
- ensure
43
- case_after c
44
- end
45
- end
46
-
47
- def case_before(c)
48
- # implement each case before
49
- end
50
-
51
- def case_after(c)
52
- return unless File.exists? "./tudu"
53
- FileUtils.rm_rf("./tudu")
54
- end
55
- end
56
- end
57
-
58
- context :add do
59
- cases = [
60
- {
61
- case_no: 1,
62
- case_title: "single add",
63
- task_names1: "task_name",
64
- task_names2: nil,
65
- task_names3: nil,
66
- expected: ["task_name"]
67
- },
68
- {
69
- case_no: 2,
70
- case_title: "nil add",
71
- task_names1: nil,
72
- task_names2: nil,
73
- task_names3: nil,
74
- expected: []
75
- },
76
- {
77
- case_no: 3,
78
- case_title: "multi add",
79
- task_names1: "task_name1",
80
- task_names2: "task_name2",
81
- task_names3: "task_name3",
82
- expected: ["task_name1","task_name2","task_name3"]
83
- },
84
- {
85
- case_no: 4,
86
- case_title: "duplicate add",
87
- task_names1: "task_name1",
88
- task_names2: "task_name1",
89
- task_names3: nil,
90
- expected: ["task_name1"]
91
- },
92
- ]
93
-
94
- cases.each do |c|
95
- it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
96
- begin
97
- case_before c
98
-
99
- # -- given --
100
- tudu_core = Tudu::Core.new
101
- tudu_core.init
102
-
103
- # -- when --
104
- actual = tudu_core.add c[:task_names1], c[:task_names2], c[:task_names3]
105
-
106
- # -- then --
107
- actual = File.read("./tudu/todos").split("\n")
108
- expect(actual).to eq(c[:expected])
109
- ensure
110
- case_after c
111
- end
112
- end
113
-
114
- def case_before(c)
115
- # implement each case before
116
- end
117
-
118
- def case_after(c)
119
- return unless File.exists? "./tudu"
120
- FileUtils.rm_rf("./tudu")
121
- end
122
- end
123
- end
124
-
125
- context :remove do
126
- cases = [
127
- {
128
- case_no: 1,
129
- case_title: "single remove",
130
- task_names1: "task_name",
131
- task_names2: nil,
132
- task_names3: nil,
133
- },
134
- {
135
- case_no: 2,
136
- case_title: "multi remove",
137
- task_names1: "task_name1",
138
- task_names2: "task_name2",
139
- task_names3: "task_name3",
140
- },
141
- {
142
- case_no: 3,
143
- case_title: "not remove",
144
- task_names1: "invalid name",
145
- task_names2: nil,
146
- task_names3: nil,
147
- },
148
- # TODO: add doing, done mix case. after implements choose, done method
149
- ]
150
-
151
- cases.each do |c|
152
- it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
153
- begin
154
- case_before c
155
-
156
- # -- given --
157
- tudu_core = Tudu::Core.new
158
- tudu_core.init
159
- tudu_core.add c[:task_names1], c[:task_names2], c[:task_names3]
160
-
161
- # -- when --
162
- tudu_core.remove c[:task_names1], c[:task_names2], c[:task_names3]
163
-
164
- # -- then --
165
- [c[:task_names1], c[:task_names2], c[:task_names3]].each do |e|
166
- actual = false
167
- ["./tudu/todos", "./tudu/doings", "./tudu/dones"].each do |f|
168
- actual = true if File.read(f).split("\n").include?(e)
169
- end
170
- expect(actual).to be_false
171
- end
172
- ensure
173
- case_after c
174
- end
175
- end
176
-
177
- def case_before(c)
178
- # implement each case before
179
- end
180
-
181
- def case_after(c)
182
- return unless File.exists? "./tudu"
183
- FileUtils.rm_rf("./tudu")
184
- end
185
- end
186
- end
187
-
188
- context :tasks do
189
- cases = [
190
- {
191
- case_no: 1,
192
- case_title: "[todos, dosings, dones] all tasks",
193
- task_names1: "task_name1",
194
- task_names2: "task_name2",
195
- task_names3: "task_name3",
196
- search_word: nil,
197
- expected: ["task_name1", "task_name2", "task_name3"]
198
- },
199
- {
200
- case_no: 2,
201
- case_title: "[todos, dosings, dones] search specific tasks",
202
- task_names1: "task_name1",
203
- task_names2: "task_name2",
204
- task_names3: "task_name3",
205
- search_word: "task_name1",
206
- expected: ["task_name1"]
207
- },
208
- {
209
- case_no: 3,
210
- case_title: "[todos, dosings, dones] search specific tasks by regexp",
211
- task_names1: "task_name1_1",
212
- task_names2: "task_name2_1",
213
- task_names3: "task_name2_2",
214
- task_names4: "task_name3_1",
215
- search_word: "task_name2_",
216
- expected: ["task_name2_1", "task_name2_2"]
217
- },
218
- # TODO: add doing, done mix case. after implements choose, done method
219
- ]
220
-
221
- cases.each do |c|
222
- it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
223
- begin
224
- case_before c
225
-
226
- # -- given --
227
- tudu_core = Tudu::Core.new
228
- tudu_core.init
229
- tudu_core.add c[:task_names1], c[:task_names2], c[:task_names3], c[:task_names4]
230
-
231
- # -- when --
232
- actual = tudu_core.tasks c[:search_word]
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
- return unless File.exists? "./tudu"
247
- FileUtils.rm_rf("./tudu")
248
- end
249
- end
250
- end
251
-
252
- context :todos do
253
- cases = [
254
- {
255
- case_no: 1,
256
- case_title: "todos all tasks",
257
- task_names1: "task_name1",
258
- task_names2: "task_name2",
259
- task_names3: "task_name3",
260
- choose: true,
261
- choose_name: "task_name1",
262
- search_word: nil,
263
- expected: ["task_name2", "task_name3"]
264
- },
265
- {
266
- case_no: 2,
267
- case_title: "todos search specific tasks",
268
- task_names1: "task_name1",
269
- task_names2: "task_name2",
270
- task_names3: "task_name3",
271
- choose: true,
272
- choose_name: "task_name1",
273
- search_word: "task_name3",
274
- expected: ["task_name3"]
275
- },
276
- {
277
- case_no: 3,
278
- case_title: "todos search specific tasks by regexp",
279
- task_names1: "task_name1_1",
280
- task_names2: "task_name2_1",
281
- task_names3: "task_name2_2",
282
- task_names4: "task_name3_1",
283
- choose: true,
284
- choose_name: "task_name1_1",
285
- search_word: "task_name2_",
286
- expected: ["task_name2_1", "task_name2_2"]
287
- },
288
- ]
289
-
290
- cases.each do |c|
291
- it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
292
- begin
293
- case_before c
294
-
295
- # -- given --
296
- tudu_core = Tudu::Core.new
297
- tudu_core.init
298
- tudu_core.add c[:task_names1], c[:task_names2], c[:task_names3], c[:task_names4]
299
- tudu_core.choose(c[:choose_name]) if c[:choose]
300
-
301
- # -- when --
302
- actual = tudu_core.todos c[:search_word]
303
-
304
- # -- then --
305
- expect(actual).to eq(c[:expected])
306
- ensure
307
- case_after c
308
- end
309
- end
310
-
311
- def case_before(c)
312
- # implement each case before
313
- end
314
-
315
- def case_after(c)
316
- # implement each case after
317
- return unless File.exists? "./tudu"
318
- FileUtils.rm_rf("./tudu")
319
- end
320
- end
321
- end
322
-
323
- context :doings do
324
- cases = [
325
- {
326
- case_no: 1,
327
- case_title: "doings all tasks",
328
- task_names1: "task_name1",
329
- task_names2: "task_name2",
330
- task_names3: "task_name3",
331
- choose: true,
332
- choose_name: "task_name1",
333
- search_word: nil,
334
- expected: ["task_name1"]
335
- },
336
- {
337
- case_no: 2,
338
- case_title: "doings search specific tasks",
339
- task_names1: "task_name1",
340
- task_names2: "task_name2",
341
- task_names3: "task_name3",
342
- choose: true,
343
- choose_name: "task_name1",
344
- search_word: nil,
345
- expected: ["task_name1"]
346
- },
347
- {
348
- case_no: 3,
349
- case_title: "doings search specific tasks by regexp",
350
- task_names1: "task_name1_1",
351
- task_names2: "task_name2_1",
352
- task_names3: "task_name2_2",
353
- task_names4: "task_name3_1",
354
- choose: true,
355
- choose_name: "task_name1_1",
356
- search_word: "task_name1_",
357
- expected: ["task_name1_1"]
358
- },
359
- ]
360
-
361
- cases.each do |c|
362
- it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
363
- begin
364
- case_before c
365
-
366
- # -- given --
367
- tudu_core = Tudu::Core.new
368
- tudu_core.init
369
- tudu_core.add c[:task_names1], c[:task_names2], c[:task_names3], c[:task_names4]
370
- tudu_core.choose(c[:choose_name]) if c[:choose]
371
-
372
- # -- when --
373
- actual = tudu_core.doings c[:search_word]
374
-
375
- # -- then --
376
- expect(actual).to eq(c[:expected])
377
- ensure
378
- case_after c
379
- end
380
- end
381
-
382
- def case_before(c)
383
- # implement each case before
384
- end
385
-
386
- def case_after(c)
387
- # implement each case after
388
- return unless File.exists? "./tudu"
389
- FileUtils.rm_rf("./tudu")
390
- end
391
- end
392
- end
393
-
394
- context :dones do
395
- cases = [
396
- {
397
- case_no: 1,
398
- case_title: "doings all tasks",
399
- task_names1: "task_name1",
400
- task_names2: "task_name2",
401
- task_names3: "task_name3",
402
- choose_names: ["task_name1", "task_name2"],
403
- done_names: ["task_name1"],
404
- search_word: nil,
405
- expected: ["task_name1"]
406
- },
407
- {
408
- case_no: 2,
409
- case_title: "doings search specific tasks",
410
- task_names1: "task_name1_1",
411
- task_names2: "task_name1_2",
412
- task_names3: "task_name2_1",
413
- choose_names: ["task_name1_1", "task_name1_2", "task_name2_1"],
414
- done_names: ["task_name1_1", "task_name1_2", "task_name2_1"],
415
- search_word: "task_name1_",
416
- expected: ["task_name1_1", "task_name1_2"]
417
- },
418
- ]
419
-
420
- cases.each do |c|
421
- it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
422
- begin
423
- case_before c
424
-
425
- # -- given --
426
- tudu_core = Tudu::Core.new
427
- tudu_core.init
428
- tudu_core.add c[:task_names1], c[:task_names2], c[:task_names3], c[:task_names4]
429
- c[:choose_names].each do |e|
430
- tudu_core.choose e
431
- tudu_core.done if c[:done_names].include? e
432
- end
433
-
434
- # -- when --
435
- actual = tudu_core.dones c[:search_word]
436
-
437
- # -- then --
438
- expect(actual).to eq(c[:expected])
439
- ensure
440
- case_after c
441
- end
442
- end
443
-
444
- def case_before(c)
445
- # implement each case before
446
- end
447
-
448
- def case_after(c)
449
- # implement each case after
450
- return unless File.exists? "./tudu"
451
- FileUtils.rm_rf("./tudu")
452
- end
453
- end
454
- end
455
-
456
- context :choose do
457
- cases = [
458
- {
459
- case_no: 1,
460
- case_title: "choose task",
461
- task_names1: "task_name1",
462
- task_names2: "task_name2",
463
- task_names3: "task_name3",
464
- choose: "task_name1",
465
- expected_todos: "task_name2\ntask_name3\n",
466
- expected_doings: "task_name1\n"
467
- },
468
- # doingにデータがあるケース
469
- # すでにdoingのケース
470
- # すでにdoneのケース
471
- # 存在しないケース
472
- ]
473
-
474
- cases.each do |c|
475
- it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
476
- begin
477
- case_before c
478
-
479
- # -- given --
480
- tudu_core = Tudu::Core.new
481
- tudu_core.init
482
- tudu_core.add c[:task_names1], c[:task_names2], c[:task_names3]
483
-
484
- # -- when --
485
- tudu_core.choose c[:choose]
486
-
487
- # -- then --
488
- actual_doings = File.read("./tudu/#{Tudu::Tasks::TUDU_DOINGS_FILE}")
489
- expect(actual_doings).to eq(c[:expected_doings])
490
- actual_todos = File.read("./tudu/#{Tudu::Tasks::TUDU_TODOS_FILE}")
491
- expect(actual_todos).to eq(c[:expected_todos])
492
- ensure
493
- case_after c
494
- end
495
- end
496
-
497
- def case_before(c)
498
- # implement each case before
499
- end
500
-
501
- def case_after(c)
502
- # implement each case after
503
- return unless File.exists? "./tudu"
504
- FileUtils.rm_rf("./tudu")
505
- end
506
- end
507
- end
508
-
509
- context :done do
510
- cases = [
511
- {
512
- case_no: 1,
513
- case_title: "one doing to done, shift todo to doing",
514
- task_names1: "task_name1",
515
- task_names2: "task_name2",
516
- task_names3: "task_name3",
517
- choose: "task_name1",
518
- expected_doings: "task_name2\n",
519
- expected_done: "task_name1\n"
520
- },
521
- {
522
- case_no: 2,
523
- case_title: "one doing to done, not shift todo to doing",
524
- task_names1: "task_name1",
525
- choose: "task_name1",
526
- expected_doings: "",
527
- expected_done: "task_name1\n"
528
- },
529
- {
530
- case_no: 3,
531
- case_title: "no doing",
532
- task_names1: "task_name1",
533
- choose: "",
534
- expected_doings: "",
535
- expected_done: ""
536
- },
537
- ]
538
-
539
- cases.each do |c|
540
- it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
541
- begin
542
- case_before c
543
-
544
- # -- given --
545
- tudu_core = Tudu::Core.new
546
- tudu_core.init
547
- tudu_core.add c[:task_names1], c[:task_names2], c[:task_names3]
548
- tudu_core.choose c[:choose]
549
-
550
- # -- when --
551
- tudu_core.done
552
-
553
- # -- then --
554
- actual_doings = File.read(Tudu::Tasks::TUDU_DOINGS_FILE_PATH)
555
- expect(actual_doings).to eq(c[:expected_doings])
556
- actual_dones = File.read(Tudu::Tasks::TUDU_DONES_FILE_PATH)
557
- expect(actual_dones).to eq(c[:expected_done])
558
- ensure
559
- case_after c
560
- end
561
- end
562
-
563
- def case_before(c)
564
- # implement each case before
565
- end
566
-
567
- def case_after(c)
568
- # implement each case after
569
- return unless File.exists? "./tudu"
570
- FileUtils.rm_rf("./tudu")
571
- end
572
- end
573
- end
574
- end
1
+ # encoding: utf-8
2
+ require "spec_helper"
3
+ require "tudu_core"
4
+
5
+ describe Tudu::Core do
6
+ context :init do
7
+ cases = [
8
+ {
9
+ case_no: 1,
10
+ case_title: "valid case",
11
+ expected_files: [
12
+ Tudu::Tasks::TUDU_FILE,
13
+ Tudu::Tasks::TUDU_TODOS_FILE,
14
+ Tudu::Tasks::TUDU_DOINGS_FILE,
15
+ Tudu::Tasks::TUDU_DONES_FILE
16
+ ],
17
+ expected_contents: [
18
+ Tudu::Tasks::TUDU_FILE_TEMPLATE,
19
+ Tudu::Tasks::TUDU_TODOS_FILE_TEMPLATE,
20
+ Tudu::Tasks::TUDU_DOINGS_FILE_TEMPLATE,
21
+ Tudu::Tasks::TUDU_DONES_FILE_TEMPLATE
22
+ ],
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_core = Tudu::Core.new
33
+
34
+ # -- when --
35
+ tudu_core.init
36
+
37
+ # -- then --
38
+ c[:expected_files].each_with_index do |f, index|
39
+ actual = File.open("./tudu/#{f}") {|f|f.read}
40
+ expect(actual).to eq(c[:expected_contents][index])
41
+ end
42
+ ensure
43
+ case_after c
44
+ end
45
+ end
46
+
47
+ def case_before(c)
48
+ # implement each case before
49
+ end
50
+
51
+ def case_after(c)
52
+ return unless File.exists? "./tudu"
53
+ FileUtils.rm_rf("./tudu")
54
+ end
55
+ end
56
+ end
57
+
58
+ context :add do
59
+ cases = [
60
+ {
61
+ case_no: 1,
62
+ case_title: "single add",
63
+ task_names1: "task_name",
64
+ task_names2: nil,
65
+ task_names3: nil,
66
+ expected: ["task_name"]
67
+ },
68
+ {
69
+ case_no: 2,
70
+ case_title: "nil add",
71
+ task_names1: nil,
72
+ task_names2: nil,
73
+ task_names3: nil,
74
+ expected: []
75
+ },
76
+ {
77
+ case_no: 3,
78
+ case_title: "multi add",
79
+ task_names1: "task_name1",
80
+ task_names2: "task_name2",
81
+ task_names3: "task_name3",
82
+ expected: ["task_name1","task_name2","task_name3"]
83
+ },
84
+ {
85
+ case_no: 4,
86
+ case_title: "duplicate add",
87
+ task_names1: "task_name1",
88
+ task_names2: "task_name1",
89
+ task_names3: nil,
90
+ expected: ["task_name1"]
91
+ },
92
+ ]
93
+
94
+ cases.each do |c|
95
+ it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
96
+ begin
97
+ case_before c
98
+
99
+ # -- given --
100
+ tudu_core = Tudu::Core.new
101
+ tudu_core.init
102
+
103
+ # -- when --
104
+ actual = tudu_core.add c[:task_names1], c[:task_names2], c[:task_names3]
105
+
106
+ # -- then --
107
+ actual = File.read("./tudu/todos").split("\n")
108
+ expect(actual).to eq(c[:expected])
109
+ ensure
110
+ case_after c
111
+ end
112
+ end
113
+
114
+ def case_before(c)
115
+ # implement each case before
116
+ end
117
+
118
+ def case_after(c)
119
+ return unless File.exists? "./tudu"
120
+ FileUtils.rm_rf("./tudu")
121
+ end
122
+ end
123
+ end
124
+
125
+ context :remove do
126
+ cases = [
127
+ {
128
+ case_no: 1,
129
+ case_title: "single remove",
130
+ task_names1: "task_name",
131
+ task_names2: nil,
132
+ task_names3: nil,
133
+ },
134
+ {
135
+ case_no: 2,
136
+ case_title: "multi remove",
137
+ task_names1: "task_name1",
138
+ task_names2: "task_name2",
139
+ task_names3: "task_name3",
140
+ },
141
+ {
142
+ case_no: 3,
143
+ case_title: "not remove",
144
+ task_names1: "invalid name",
145
+ task_names2: nil,
146
+ task_names3: nil,
147
+ },
148
+ # TODO: add doing, done mix case. after implements choose, done method
149
+ ]
150
+
151
+ cases.each do |c|
152
+ it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
153
+ begin
154
+ case_before c
155
+
156
+ # -- given --
157
+ tudu_core = Tudu::Core.new
158
+ tudu_core.init
159
+ tudu_core.add c[:task_names1], c[:task_names2], c[:task_names3]
160
+
161
+ # -- when --
162
+ tudu_core.remove c[:task_names1], c[:task_names2], c[:task_names3]
163
+
164
+ # -- then --
165
+ [c[:task_names1], c[:task_names2], c[:task_names3]].each do |e|
166
+ actual = false
167
+ ["./tudu/todos", "./tudu/doings", "./tudu/dones"].each do |f|
168
+ actual = true if File.read(f).split("\n").include?(e)
169
+ end
170
+ expect(actual).to be_false
171
+ end
172
+ ensure
173
+ case_after c
174
+ end
175
+ end
176
+
177
+ def case_before(c)
178
+ # implement each case before
179
+ end
180
+
181
+ def case_after(c)
182
+ return unless File.exists? "./tudu"
183
+ FileUtils.rm_rf("./tudu")
184
+ end
185
+ end
186
+ end
187
+
188
+ context :tasks do
189
+ cases = [
190
+ {
191
+ case_no: 1,
192
+ case_title: "[todos, dosings, dones] all tasks",
193
+ task_names1: "task_name1",
194
+ task_names2: "task_name2",
195
+ task_names3: "task_name3",
196
+ search_word: nil,
197
+ expected: ["task_name1", "task_name2", "task_name3"]
198
+ },
199
+ {
200
+ case_no: 2,
201
+ case_title: "[todos, dosings, dones] search specific tasks",
202
+ task_names1: "task_name1",
203
+ task_names2: "task_name2",
204
+ task_names3: "task_name3",
205
+ search_word: "task_name1",
206
+ expected: ["task_name1"]
207
+ },
208
+ {
209
+ case_no: 3,
210
+ case_title: "[todos, dosings, dones] search specific tasks by regexp",
211
+ task_names1: "task_name1_1",
212
+ task_names2: "task_name2_1",
213
+ task_names3: "task_name2_2",
214
+ task_names4: "task_name3_1",
215
+ search_word: "task_name2_",
216
+ expected: ["task_name2_1", "task_name2_2"]
217
+ },
218
+ ]
219
+
220
+ cases.each do |c|
221
+ it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
222
+ begin
223
+ case_before c
224
+
225
+ # -- given --
226
+ tudu_core = Tudu::Core.new
227
+ tudu_core.init
228
+ tudu_core.add c[:task_names1], c[:task_names2], c[:task_names3], c[:task_names4]
229
+
230
+ # -- when --
231
+ actual = tudu_core.tasks c[:search_word]
232
+
233
+ # -- then --
234
+ expect(actual).to eq(c[:expected])
235
+ ensure
236
+ case_after c
237
+ end
238
+ end
239
+
240
+ def case_before(c)
241
+ # implement each case before
242
+ end
243
+
244
+ def case_after(c)
245
+ return unless File.exists? "./tudu"
246
+ FileUtils.rm_rf("./tudu")
247
+ end
248
+ end
249
+ end
250
+
251
+ context :todos do
252
+ cases = [
253
+ {
254
+ case_no: 1,
255
+ case_title: "todos all tasks",
256
+ task_names1: "task_name1",
257
+ task_names2: "task_name2",
258
+ task_names3: "task_name3",
259
+ choose: true,
260
+ choose_name: "task_name1",
261
+ search_word: nil,
262
+ expected: ["task_name2", "task_name3"]
263
+ },
264
+ {
265
+ case_no: 2,
266
+ case_title: "todos search specific tasks",
267
+ task_names1: "task_name1",
268
+ task_names2: "task_name2",
269
+ task_names3: "task_name3",
270
+ choose: true,
271
+ choose_name: "task_name1",
272
+ search_word: "task_name3",
273
+ expected: ["task_name3"]
274
+ },
275
+ {
276
+ case_no: 3,
277
+ case_title: "todos search specific tasks by regexp",
278
+ task_names1: "task_name1_1",
279
+ task_names2: "task_name2_1",
280
+ task_names3: "task_name2_2",
281
+ task_names4: "task_name3_1",
282
+ choose: true,
283
+ choose_name: "task_name1_1",
284
+ search_word: "task_name2_",
285
+ expected: ["task_name2_1", "task_name2_2"]
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
+ tudu_core = Tudu::Core.new
296
+ tudu_core.init
297
+ tudu_core.add c[:task_names1], c[:task_names2], c[:task_names3], c[:task_names4]
298
+ tudu_core.choose(c[:choose_name]) if c[:choose]
299
+
300
+ # -- when --
301
+ actual = tudu_core.todos c[:search_word]
302
+
303
+ # -- then --
304
+ 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
+ end
313
+
314
+ def case_after(c)
315
+ # implement each case after
316
+ return unless File.exists? "./tudu"
317
+ FileUtils.rm_rf("./tudu")
318
+ end
319
+ end
320
+ end
321
+
322
+ context :doings do
323
+ cases = [
324
+ {
325
+ case_no: 1,
326
+ case_title: "doings all tasks",
327
+ task_names1: "task_name1",
328
+ task_names2: "task_name2",
329
+ task_names3: "task_name3",
330
+ choose: true,
331
+ choose_name: "task_name1",
332
+ search_word: nil,
333
+ expected: ["task_name1"]
334
+ },
335
+ {
336
+ case_no: 2,
337
+ case_title: "doings search specific tasks",
338
+ task_names1: "task_name1",
339
+ task_names2: "task_name2",
340
+ task_names3: "task_name3",
341
+ choose: true,
342
+ choose_name: "task_name1",
343
+ search_word: nil,
344
+ expected: ["task_name1"]
345
+ },
346
+ {
347
+ case_no: 3,
348
+ case_title: "doings search specific tasks by regexp",
349
+ task_names1: "task_name1_1",
350
+ task_names2: "task_name2_1",
351
+ task_names3: "task_name2_2",
352
+ task_names4: "task_name3_1",
353
+ choose: true,
354
+ choose_name: "task_name1_1",
355
+ search_word: "task_name1_",
356
+ expected: ["task_name1_1"]
357
+ },
358
+ ]
359
+
360
+ cases.each do |c|
361
+ it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
362
+ begin
363
+ case_before c
364
+
365
+ # -- given --
366
+ tudu_core = Tudu::Core.new
367
+ tudu_core.init
368
+ tudu_core.add c[:task_names1], c[:task_names2], c[:task_names3], c[:task_names4]
369
+ tudu_core.choose(c[:choose_name]) if c[:choose]
370
+
371
+ # -- when --
372
+ actual = tudu_core.doings c[:search_word]
373
+
374
+ # -- then --
375
+ expect(actual).to eq(c[:expected])
376
+ ensure
377
+ case_after c
378
+ end
379
+ end
380
+
381
+ def case_before(c)
382
+ # implement each case before
383
+ end
384
+
385
+ def case_after(c)
386
+ # implement each case after
387
+ return unless File.exists? "./tudu"
388
+ FileUtils.rm_rf("./tudu")
389
+ end
390
+ end
391
+ end
392
+
393
+ context :dones do
394
+ cases = [
395
+ {
396
+ case_no: 1,
397
+ case_title: "doings all tasks",
398
+ task_names1: "task_name1",
399
+ task_names2: "task_name2",
400
+ task_names3: "task_name3",
401
+ choose_names: ["task_name1", "task_name2"],
402
+ done_names: ["task_name1"],
403
+ search_word: nil,
404
+ expected: ["task_name1"]
405
+ },
406
+ {
407
+ case_no: 2,
408
+ case_title: "doings search specific tasks",
409
+ task_names1: "task_name1_1",
410
+ task_names2: "task_name1_2",
411
+ task_names3: "task_name2_1",
412
+ choose_names: ["task_name1_1", "task_name1_2", "task_name2_1"],
413
+ done_names: ["task_name1_1", "task_name1_2", "task_name2_1"],
414
+ search_word: "task_name1_",
415
+ expected: ["task_name1_1", "task_name1_2"]
416
+ },
417
+ ]
418
+
419
+ cases.each do |c|
420
+ it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
421
+ begin
422
+ case_before c
423
+
424
+ # -- given --
425
+ tudu_core = Tudu::Core.new
426
+ tudu_core.init
427
+ tudu_core.add c[:task_names1], c[:task_names2], c[:task_names3], c[:task_names4]
428
+ c[:choose_names].each do |e|
429
+ tudu_core.choose e
430
+ tudu_core.done if c[:done_names].include? e
431
+ end
432
+
433
+ # -- when --
434
+ actual = tudu_core.dones c[:search_word]
435
+
436
+ # -- then --
437
+ expect(actual).to eq(c[:expected])
438
+ ensure
439
+ case_after c
440
+ end
441
+ end
442
+
443
+ def case_before(c)
444
+ # implement each case before
445
+ end
446
+
447
+ def case_after(c)
448
+ # implement each case after
449
+ return unless File.exists? "./tudu"
450
+ FileUtils.rm_rf("./tudu")
451
+ end
452
+ end
453
+ end
454
+
455
+ context :choose do
456
+ cases = [
457
+ {
458
+ case_no: 1,
459
+ case_title: "choose task",
460
+ task_names1: "task_name1",
461
+ task_names2: "task_name2",
462
+ task_names3: "task_name3",
463
+ choose: "task_name1",
464
+ expected_todos: "task_name2\ntask_name3\n",
465
+ expected_doings: "task_name1\n"
466
+ },
467
+ ]
468
+
469
+ cases.each do |c|
470
+ it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
471
+ begin
472
+ case_before c
473
+
474
+ # -- given --
475
+ tudu_core = Tudu::Core.new
476
+ tudu_core.init
477
+ tudu_core.add c[:task_names1], c[:task_names2], c[:task_names3]
478
+
479
+ # -- when --
480
+ tudu_core.choose c[:choose]
481
+
482
+ # -- then --
483
+ actual_doings = File.read("./tudu/#{Tudu::Tasks::TUDU_DOINGS_FILE}")
484
+ expect(actual_doings).to eq(c[:expected_doings])
485
+ actual_todos = File.read("./tudu/#{Tudu::Tasks::TUDU_TODOS_FILE}")
486
+ expect(actual_todos).to eq(c[:expected_todos])
487
+ ensure
488
+ case_after c
489
+ end
490
+ end
491
+
492
+ def case_before(c)
493
+ # implement each case before
494
+ end
495
+
496
+ def case_after(c)
497
+ # implement each case after
498
+ return unless File.exists? "./tudu"
499
+ FileUtils.rm_rf("./tudu")
500
+ end
501
+ end
502
+ end
503
+
504
+ context :done do
505
+ cases = [
506
+ {
507
+ case_no: 1,
508
+ case_title: "one doing to done, shift todo to doing",
509
+ task_names1: "task_name1",
510
+ task_names2: "task_name2",
511
+ task_names3: "task_name3",
512
+ choose: "task_name1",
513
+ expected_doings: "task_name2\n",
514
+ expected_done: "task_name1\n"
515
+ },
516
+ {
517
+ case_no: 2,
518
+ case_title: "one doing to done, not shift todo to doing",
519
+ task_names1: "task_name1",
520
+ choose: "task_name1",
521
+ expected_doings: "",
522
+ expected_done: "task_name1\n"
523
+ },
524
+ {
525
+ case_no: 3,
526
+ case_title: "no doing",
527
+ task_names1: "task_name1",
528
+ choose: "",
529
+ expected_doings: "",
530
+ expected_done: ""
531
+ },
532
+ ]
533
+
534
+ cases.each do |c|
535
+ it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
536
+ begin
537
+ case_before c
538
+
539
+ # -- given --
540
+ tudu_core = Tudu::Core.new
541
+ tudu_core.init
542
+ tudu_core.add c[:task_names1], c[:task_names2], c[:task_names3]
543
+ tudu_core.choose c[:choose] unless c[:choose].empty?
544
+
545
+ # -- when --
546
+ tudu_core.done
547
+
548
+ # -- then --
549
+ actual_doings = File.read(Tudu::Tasks::TUDU_DOINGS_FILE_PATH)
550
+ expect(actual_doings).to eq(c[:expected_doings])
551
+ actual_dones = File.read(Tudu::Tasks::TUDU_DONES_FILE_PATH)
552
+ expect(actual_dones).to eq(c[:expected_done])
553
+ ensure
554
+ case_after c
555
+ end
556
+ end
557
+
558
+ def case_before(c)
559
+ # implement each case before
560
+ end
561
+
562
+ def case_after(c)
563
+ # implement each case after
564
+ return unless File.exists? "./tudu"
565
+ FileUtils.rm_rf("./tudu")
566
+ end
567
+ end
568
+ end
569
+ end