tudu 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+ # =TodoManage Module
1
3
  module Tudu
2
- VERSION = "0.0.4"
4
+ VERSION = '0.0.5'
3
5
  end
@@ -1,97 +1,126 @@
1
- # encoding: utf-8
2
- require "tudu/version"
3
- require "tasks"
4
-
5
- module Tudu
6
- # Tudu::Core
7
- class Core
8
- #== generate files [Tudufile, todos, doings, dones]
9
- def init
10
- Dir.mkdir Tudu::Tasks::TUDU_DIR unless File.exists? Tudu::Tasks::TUDU_DIR
11
- Tudu::Tasks::TUDU_KEYS.each do |key|
12
- File.open("./tudu/#{Tudu::Tasks::INIT_FILES[key]}", "w:UTF-8") {|f|f.print Tudu::Tasks::INIT_FILES_TEMPLATE[key]}
13
- end
14
- end
15
-
16
- #== add task to todo
17
- #=== Params
18
- #- task_names : add task name list
19
- def add(*task_names)
20
- Tudu::Tasks.add *task_names
21
- end
22
-
23
- #== remove task to todo
24
- #=== Params
25
- #- task_names : remove task name list
26
- def remove(*task_names)
27
- Tudu::Tasks.remove *task_names
28
- end
29
-
30
- #== choose todo => doing task
31
- #=== Params
32
- #- task_name : target task name
33
- def choose(task_name)
34
- Tudu::Tasks.choose task_name
35
- end
36
-
37
- #== doing to done
38
- #- if doings size == 0, nothing todo.
39
- #- after move doing to done, next todo move to doing.
40
- def done
41
- Tudu::Tasks.done
42
- end
43
-
44
- #== search tasks
45
- #=== Params
46
- #- search_word : search word. enable regexp.
47
- #- options : options.
48
- def tasks(search_word, options)
49
- tasks = Tudu::Tasks.filter_tasks(Tudu::Tasks.get_tasks, search_word).map(&:name)
50
- (!options.nil? and options[:category]) ? categorized_tasks(tasks, search_word) : tasks
51
- end
52
-
53
- #== search todos
54
- #=== Params
55
- #- search_word : search word. enable regexp.
56
- def todos(search_word)
57
- Tudu::Tasks.filter_tasks(Tudu::Tasks.get_todos, search_word).map(&:name)
58
- end
59
-
60
- #== search doings
61
- #=== Params
62
- #- search_word : search word. enable regexp.
63
- def doings(search_word)
64
- Tudu::Tasks.filter_tasks(Tudu::Tasks.get_doings, search_word).map(&:name)
65
- end
66
-
67
- #== search dones
68
- #=== Params
69
- #- search_word : search word. enable regexp.
70
- def dones(search_word)
71
- Tudu::Tasks.filter_tasks(Tudu::Tasks.get_dones, search_word).map(&:name)
72
- end
73
-
74
- #== display tasks progress
75
- #=== Returns
76
- # return progress
77
- def progress
78
- Tudu::Tasks.progress
79
- end
80
-
81
- def categorized_tasks(tasks, search_word)
82
- ret = []
83
- tasks = Tudu::Tasks.filter_tasks(Tudu::Tasks.get_tasks, search_word)
84
- ret << "========TODOS========"
85
- ret << tasks.select {|task|task.type == Tudu::Tasks::TUDU_TODOS_FILE}.map(&:name).join("\n")
86
- ret << ""
87
- ret << "========DOINGS========"
88
- ret << tasks.select {|task|task.type == Tudu::Tasks::TUDU_DOINGS_FILE}.map(&:name).join("\n")
89
- ret << ""
90
- ret << "========DONES========"
91
- ret << tasks.select {|task|task.type == Tudu::Tasks::TUDU_DONES_FILE}.map(&:name).join("\n")
92
- ret
93
- end
94
-
95
- alias :now :doings
96
- end
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
@@ -1,41 +1,41 @@
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 or _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
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
@@ -1,4 +1,5 @@
1
- require "simplecov"
1
+ # encoding: utf-8
2
+ require 'simplecov'
2
3
  SimpleCov.start
3
4
  RSpec.configure do |config|
4
5
  config.treat_symbols_as_metadata_keys_with_true_values = true
@@ -1,861 +1,856 @@
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
-
800
- context :progress do
801
- cases = [
802
- {
803
- case_no: 1,
804
- case_title: "display progress",
805
- todos: ["task5", "task6"],
806
- doings: ["task3", "task4"],
807
- dones: ["task1", "task2"],
808
- expected: "2/6|===> |33%",
809
- },
810
- {
811
- case_no: 2,
812
- case_title: "display none progress",
813
- todos: ["task3", "task4"],
814
- doings: ["task1", "task2"],
815
- dones: [],
816
- expected: "0/4|> |0%",
817
- },
818
- {
819
- case_no: 3,
820
- case_title: "display complete progress",
821
- todos: [],
822
- doings: [],
823
- dones: ["task1", "task2"],
824
- expected: "2/2|==========>|100%",
825
- },
826
- ]
827
-
828
- cases.each do |c|
829
- it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do
830
- begin
831
- case_before c
832
-
833
- # -- given --
834
- # nothing
835
-
836
- # -- when --
837
- actual = Tudu::Tasks.progress
838
-
839
- # -- then --
840
- ret = expect(actual).to eq(c[:expected])
841
- ensure
842
- case_after c
843
- end
844
- end
845
-
846
- def case_before(c)
847
- # implement each case before
848
- Tudu::Core.new.init
849
- File.open("./#{Tudu::Tasks::TUDU_DIR}/todos", "w") {|f|f.puts c[:todos].join("\n")}
850
- File.open("./#{Tudu::Tasks::TUDU_DIR}/doings", "w") {|f|f.puts c[:doings].join("\n")}
851
- File.open("./#{Tudu::Tasks::TUDU_DIR}/dones", "w") {|f|f.puts c[:dones].join("\n")}
852
- end
853
-
854
- def case_after(c)
855
- # implement each case after
856
- return unless File.exists? Tudu::Tasks::TUDU_DIR
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