tudu 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +35 -5
- data/lib/tasks.rb +289 -281
- data/lib/tudu/version.rb +1 -1
- data/spec/{task_spec.rb → tasks_spec.rb} +799 -762
- data/spec/tudu_core_spec.rb +569 -574
- data/spec/tudu_dsl_spec.rb +120 -120
- metadata +14 -15
- data/lib/task.rb +0 -281
data/spec/tudu_core_spec.rb
CHANGED
@@ -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
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
tudu_core
|
228
|
-
tudu_core.
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
tudu_core
|
297
|
-
tudu_core.
|
298
|
-
tudu_core.
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
tudu_core
|
368
|
-
tudu_core.
|
369
|
-
tudu_core.
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
415
|
-
|
416
|
-
|
417
|
-
|
418
|
-
|
419
|
-
|
420
|
-
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
426
|
-
tudu_core
|
427
|
-
tudu_core.
|
428
|
-
|
429
|
-
|
430
|
-
tudu_core.
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
# --
|
480
|
-
tudu_core
|
481
|
-
|
482
|
-
|
483
|
-
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
|
501
|
-
|
502
|
-
|
503
|
-
|
504
|
-
|
505
|
-
|
506
|
-
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
|
517
|
-
|
518
|
-
|
519
|
-
|
520
|
-
|
521
|
-
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
|
526
|
-
|
527
|
-
|
528
|
-
|
529
|
-
|
530
|
-
|
531
|
-
|
532
|
-
|
533
|
-
|
534
|
-
|
535
|
-
|
536
|
-
|
537
|
-
|
538
|
-
|
539
|
-
|
540
|
-
|
541
|
-
|
542
|
-
|
543
|
-
|
544
|
-
|
545
|
-
|
546
|
-
tudu_core.
|
547
|
-
|
548
|
-
|
549
|
-
|
550
|
-
|
551
|
-
|
552
|
-
|
553
|
-
|
554
|
-
|
555
|
-
|
556
|
-
|
557
|
-
|
558
|
-
|
559
|
-
|
560
|
-
|
561
|
-
|
562
|
-
|
563
|
-
|
564
|
-
|
565
|
-
|
566
|
-
|
567
|
-
|
568
|
-
|
569
|
-
|
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
|