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
@@ -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
|
-
|
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
|
-
|
547
|
-
|
548
|
-
|
549
|
-
|
550
|
-
|
551
|
-
|
552
|
-
|
553
|
-
|
554
|
-
|
555
|
-
|
556
|
-
|
557
|
-
|
558
|
-
|
559
|
-
|
560
|
-
|
561
|
-
|
562
|
-
|
563
|
-
|
564
|
-
|
565
|
-
|
566
|
-
|
567
|
-
|
568
|
-
|
569
|
-
|
570
|
-
|
571
|
-
|
572
|
-
|
573
|
-
|
574
|
-
|
575
|
-
|
576
|
-
|
577
|
-
|
578
|
-
|
579
|
-
|
580
|
-
|
581
|
-
|
582
|
-
|
583
|
-
|
584
|
-
|
585
|
-
|
586
|
-
|
587
|
-
|
588
|
-
|
589
|
-
|
590
|
-
|
591
|
-
|
592
|
-
|
593
|
-
|
594
|
-
|
595
|
-
|
596
|
-
|
597
|
-
|
598
|
-
|
599
|
-
|
600
|
-
|
601
|
-
|
602
|
-
|
603
|
-
|
604
|
-
|
605
|
-
|
606
|
-
|
607
|
-
|
608
|
-
|
609
|
-
|
610
|
-
|
611
|
-
|
612
|
-
|
613
|
-
|
614
|
-
|
615
|
-
|
616
|
-
|
617
|
-
|
618
|
-
|
619
|
-
|
620
|
-
|
621
|
-
|
622
|
-
|
623
|
-
|
624
|
-
|
625
|
-
|
626
|
-
|
627
|
-
|
628
|
-
|
629
|
-
|
630
|
-
|
631
|
-
|
632
|
-
|
633
|
-
|
634
|
-
|
635
|
-
|
636
|
-
|
637
|
-
|
638
|
-
|
639
|
-
|
640
|
-
|
641
|
-
|
642
|
-
|
643
|
-
|
644
|
-
|
645
|
-
|
646
|
-
|
647
|
-
|
648
|
-
|
649
|
-
|
650
|
-
|
651
|
-
|
652
|
-
|
653
|
-
|
654
|
-
|
655
|
-
|
656
|
-
|
657
|
-
|
658
|
-
|
659
|
-
|
660
|
-
|
661
|
-
|
662
|
-
|
663
|
-
|
664
|
-
|
665
|
-
|
666
|
-
|
667
|
-
|
668
|
-
|
669
|
-
|
670
|
-
|
671
|
-
|
672
|
-
|
673
|
-
|
674
|
-
|
675
|
-
|
676
|
-
|
677
|
-
|
678
|
-
|
679
|
-
|
680
|
-
|
681
|
-
|
682
|
-
|
683
|
-
|
684
|
-
|
685
|
-
|
686
|
-
|
687
|
-
|
688
|
-
|
689
|
-
|
690
|
-
|
691
|
-
|
692
|
-
|
693
|
-
|
694
|
-
|
695
|
-
|
696
|
-
|
697
|
-
|
698
|
-
|
699
|
-
|
700
|
-
|
701
|
-
|
702
|
-
|
703
|
-
|
704
|
-
|
705
|
-
|
706
|
-
|
707
|
-
|
708
|
-
|
709
|
-
|
710
|
-
|
711
|
-
|
712
|
-
|
713
|
-
|
714
|
-
|
715
|
-
|
716
|
-
|
717
|
-
|
718
|
-
|
719
|
-
|
720
|
-
|
721
|
-
|
722
|
-
|
723
|
-
|
724
|
-
|
725
|
-
|
726
|
-
|
727
|
-
|
728
|
-
|
729
|
-
|
730
|
-
|
731
|
-
|
732
|
-
|
733
|
-
|
734
|
-
|
735
|
-
|
736
|
-
|
737
|
-
|
738
|
-
|
739
|
-
|
740
|
-
|
741
|
-
|
742
|
-
|
743
|
-
|
744
|
-
|
745
|
-
|
746
|
-
|
747
|
-
|
748
|
-
|
749
|
-
|
750
|
-
|
751
|
-
|
752
|
-
|
753
|
-
|
754
|
-
|
755
|
-
|
756
|
-
|
757
|
-
|
758
|
-
|
759
|
-
|
760
|
-
|
761
|
-
|
762
|
-
|
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
|