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