spec/tasks_spec.rb in tudu-0.0.5 vs spec/tasks_spec.rb in tudu-0.0.6

- old
+ new

@@ -1,37 +1,39 @@ # encoding: utf-8 require 'spec_helper' require 'tudu_core' require 'tasks' +require 'task' +# rubocop:disable LineLength, UnusedMethodArgument describe Tudu::Tasks do context :todo? do cases = [ { case_no: 1, case_title: 'todo task', name: 'task_name', type: 'todos', - expected: true, + expected: true }, { case_no: 2, case_title: 'not todo task', name: 'task_name', type: 'doings', - expected: false, - }, + expected: false + } ] cases.each do |c| it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do begin case_before c # -- given -- - tudu_task = Tudu::Tasks.new(c[:type], c[:name]) + tudu_task = Tudu::Task.new(c[:type], c[:name]) # -- when -- actual = tudu_task.todo? # -- then -- @@ -56,28 +58,28 @@ { case_no: 1, case_title: 'doing task', name: 'task_name', type: 'doings', - expected: true, + expected: true }, { case_no: 2, case_title: 'not doing task', name: 'task_name', type: 'todos', - expected: false, - }, + expected: false + } ] cases.each do |c| it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do begin case_before c # -- given -- - tudu_task = Tudu::Tasks.new(c[:type], c[:name]) + tudu_task = Tudu::Task.new(c[:type], c[:name]) # -- when -- actual = tudu_task.doing? # -- then -- @@ -103,28 +105,28 @@ { case_no: 1, case_title: 'done task', name: 'task_name', type: 'dones', - expected: true, + expected: true }, { case_no: 2, case_title: 'not done task', name: 'task_name', type: 'doings', - expected: false, - }, + expected: false + } ] cases.each do |c| it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do begin case_before c # -- given -- - tudu_task = Tudu::Tasks.new(c[:type], c[:name]) + tudu_task = Tudu::Task.new(c[:type], c[:name]) # -- when -- actual = tudu_task.done? # -- then -- @@ -148,27 +150,27 @@ cases = [ { case_no: 1, case_title: 'get todos from file', type: 'todos', - texts: %w{task1 task2 task3}, - expected: %w{task1 task2 task3}, + texts: %w(task1 task2 task3), + expected: %w(task1 task2 task3) }, { case_no: 2, case_title: 'get doings from file', type: 'doings', - texts: %w{task1 task2 task3}, - expected: %w{task1 task2 task3}, + texts: %w(task1 task2 task3), + expected: %w(task1 task2 task3) }, { case_no: 3, case_title: 'get done from file', type: 'dones', - texts: %w{task1 task2 task3}, - expected: %w{task1 task2 task3}, - }, + texts: %w(task1 task2 task3), + expected: %w(task1 task2 task3) + } ] cases.each do |c| it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do begin @@ -187,57 +189,57 @@ end end def case_before(c) # implement each case before - Dir.mkdir("./#{Tudu::Tasks::TUDU_DIR}") - File.open("./#{Tudu::Tasks::TUDU_DIR}/#{c[:type]}", 'w') { |f|f.puts c[:texts].join("\n") } + Dir.mkdir("./#{Tudu::TuduPaths::TUDU_DIR}") + File.open("./#{Tudu::TuduPaths::TUDU_DIR}/#{c[:type]}", 'w') { |f|f.puts c[:texts].join("\n") } end def case_after(c) # implement each case after - return unless File.exists? Tudu::Tasks::TUDU_DIR - FileUtils.rm_rf(Tudu::Tasks::TUDU_DIR) + return unless File.exist? Tudu::TuduPaths::TUDU_DIR + FileUtils.rm_rf(Tudu::TuduPaths::TUDU_DIR) end end end context :get_tasks do cases = [ { case_no: 1, case_title: 'get todos from file', type: 'todos', - texts: %w{task1 task2 task3}, + texts: %w(task1 task2 task3), expected: [ - Tudu::Tasks.new('todos', 'task1'), - Tudu::Tasks.new('todos', 'task2'), - Tudu::Tasks.new('todos', 'task3'), - ], + Tudu::Task.new('todos', 'task1'), + Tudu::Task.new('todos', 'task2'), + Tudu::Task.new('todos', 'task3') + ] }, { case_no: 2, case_title: 'get doings from file', type: 'doings', - texts: %w{task1 task2 task3}, + texts: %w(task1 task2 task3), expected: [ - Tudu::Tasks.new('doings', 'task1'), - Tudu::Tasks.new('doings', 'task2'), - Tudu::Tasks.new('doings', 'task3'), - ], + Tudu::Task.new('doings', 'task1'), + Tudu::Task.new('doings', 'task2'), + Tudu::Task.new('doings', 'task3') + ] }, { case_no: 3, case_title: 'get done from file', type: 'dones', - texts: %w{task1 task2 task3}, + texts: %w(task1 task2 task3), expected: [ - Tudu::Tasks.new('dones', 'task1'), - Tudu::Tasks.new('dones', 'task2'), - Tudu::Tasks.new('dones', 'task3'), - ], - }, + Tudu::Task.new('dones', 'task1'), + Tudu::Task.new('dones', 'task2'), + Tudu::Task.new('dones', 'task3') + ] + } ] cases.each do |c| it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do begin @@ -256,35 +258,35 @@ end end def case_before(c) # implement each case before - Dir.mkdir("./#{Tudu::Tasks::TUDU_DIR}") - File.open("./#{Tudu::Tasks::TUDU_DIR}/#{c[:type]}", 'w') { |f|f.puts c[:texts].join("\n") } + Dir.mkdir("./#{Tudu::TuduPaths::TUDU_DIR}") + File.open("./#{Tudu::TuduPaths::TUDU_DIR}/#{c[:type]}", 'w') { |f|f.puts c[:texts].join("\n") } end def case_after(c) # implement each case after - return unless File.exists? Tudu::Tasks::TUDU_DIR - FileUtils.rm_rf(Tudu::Tasks::TUDU_DIR) + return unless File.exist? Tudu::TuduPaths::TUDU_DIR + FileUtils.rm_rf(Tudu::TuduPaths::TUDU_DIR) end end end - context :get_todos do + context :todos do cases = [ { case_no: 1, case_title: 'get doings from file', type: 'doings', - texts: %w{task1 task2 task3}, + texts: %w(task1 task2 task3), expected: [ - Tudu::Tasks.new('doings', 'task1'), - Tudu::Tasks.new('doings', 'task2'), - Tudu::Tasks.new('doings', 'task3'), - ], - }, + Tudu::Task.new('doings', 'task1'), + Tudu::Task.new('doings', 'task2'), + Tudu::Task.new('doings', 'task3') + ] + } ] cases.each do |c| it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do begin @@ -292,46 +294,46 @@ # -- given -- # nothing # -- when -- - actual = Tudu::Tasks.get_doings + actual = Tudu::Tasks.doings # -- then -- expect(actual).to eq(c[:expected]) ensure case_after c end end def case_before(c) # implement each case before - Dir.mkdir("./#{Tudu::Tasks::TUDU_DIR}") - File.open("./#{Tudu::Tasks::TUDU_DIR}/#{c[:type]}", 'w') { |f|f.puts c[:texts].join("\n") } + Dir.mkdir("./#{Tudu::TuduPaths::TUDU_DIR}") + File.open("./#{Tudu::TuduPaths::TUDU_DIR}/#{c[:type]}", 'w') { |f|f.puts c[:texts].join("\n") } end def case_after(c) # implement each case after - return unless File.exists? Tudu::Tasks::TUDU_DIR - FileUtils.rm_rf(Tudu::Tasks::TUDU_DIR) + return unless File.exist? Tudu::TuduPaths::TUDU_DIR + FileUtils.rm_rf(Tudu::TuduPaths::TUDU_DIR) end end end - context :get_dones do + context :dones do cases = [ { case_no: 1, case_title: 'get done from file', type: 'dones', - texts: %w{task1 task2 task3}, + texts: %w(task1 task2 task3), expected: [ - Tudu::Tasks.new('dones', 'task1'), - Tudu::Tasks.new('dones', 'task2'), - Tudu::Tasks.new('dones', 'task3'), - ], - }, + Tudu::Task.new('dones', 'task1'), + Tudu::Task.new('dones', 'task2'), + Tudu::Task.new('dones', 'task3') + ] + } ] cases.each do |c| it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do begin @@ -339,67 +341,67 @@ # -- given -- # nothing # -- when -- - actual = Tudu::Tasks.get_dones + actual = Tudu::Tasks.dones # -- then -- expect(actual).to eq(c[:expected]) ensure case_after c end end def case_before(c) # implement each case before - Dir.mkdir("./#{Tudu::Tasks::TUDU_DIR}") - File.open("./#{Tudu::Tasks::TUDU_DIR}/#{c[:type]}", 'w') { |f|f.puts c[:texts].join("\n") } + Dir.mkdir("./#{Tudu::TuduPaths::TUDU_DIR}") + File.open("./#{Tudu::TuduPaths::TUDU_DIR}/#{c[:type]}", 'w') { |f|f.puts c[:texts].join("\n") } end def case_after(c) # implement each case after - return unless File.exists? Tudu::Tasks::TUDU_DIR - FileUtils.rm_rf(Tudu::Tasks::TUDU_DIR) + return unless File.exist? Tudu::TuduPaths::TUDU_DIR + FileUtils.rm_rf(Tudu::TuduPaths::TUDU_DIR) end end end context :find_tasks do cases = [ { case_no: 1, case_title: 'find todos from tasks', type: 'todos', - texts: %w{task1 task2 task3}, + texts: %w(task1 task2 task3), search_name: 'task1', - expected: Tudu::Tasks.new('todos', 'task1') + expected: Tudu::Task.new('todos', 'task1') }, { case_no: 2, case_title: 'find doings from tasks', type: 'doings', - texts: %w{task1 task2 task3}, + texts: %w(task1 task2 task3), search_name: 'task1', - expected: Tudu::Tasks.new('doings', 'task1') + expected: Tudu::Task.new('doings', 'task1') }, { case_no: 3, case_title: 'find done from tasks', type: 'dones', - texts: %w{task1 task2 task3}, + texts: %w(task1 task2 task3), search_name: 'task1', - expected: Tudu::Tasks.new('dones', 'task1') + expected: Tudu::Task.new('dones', 'task1') }, { case_no: 4, case_title: 'not find', type: 'dones', - texts: %w{task1 task2 task3}, + texts: %w(task1 task2 task3), search_name: 'task4', expected: nil - }, + } ] cases.each do |c| it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do begin @@ -419,109 +421,108 @@ end def case_before(c) # implement each case before Tudu::Core.new.init - Dir.mkdir(Tudu::Tasks::TUDU_DIR) unless File.exists?(Tudu::Tasks::TUDU_DIR) - File.open("./#{Tudu::Tasks::TUDU_DIR}/#{c[:type]}", 'w') { |f|f.puts c[:texts].join("\n") } + Dir.mkdir(Tudu::TuduPaths::TUDU_DIR) unless File.exist?(Tudu::TuduPaths::TUDU_DIR) + File.open("./#{Tudu::TuduPaths::TUDU_DIR}/#{c[:type]}", 'w') { |f|f.puts c[:texts].join("\n") } end def case_after(c) # implement each case after - return unless File.exists? Tudu::Tasks::TUDU_DIR - FileUtils.rm_rf(Tudu::Tasks::TUDU_DIR) + return unless File.exist? Tudu::TuduPaths::TUDU_DIR + FileUtils.rm_rf(Tudu::TuduPaths::TUDU_DIR) end end end context :choose do cases = [ { case_no: 1, case_title: 'choose task', type: 'todos', - texts: %w{task1 task2 task3}, + texts: %w(task1 task2 task3), choose: 'task1', expected: [ - Tudu::Tasks.new('todos', 'task2'), - Tudu::Tasks.new('todos', 'task3'), - Tudu::Tasks.new('doings', 'task1'), + Tudu::Task.new('todos', 'task2'), + Tudu::Task.new('todos', 'task3'), + Tudu::Task.new('doings', 'task1') ] }, { case_no: 2, case_title: 'aleady exists doing', type: 'doings', - texts: %w{task1 task2 task3}, + texts: %w(task1 task2 task3), choose: 'task1', expected: [ - Tudu::Tasks.new('doings', 'task1'), - Tudu::Tasks.new('doings', 'task2'), - Tudu::Tasks.new('doings', 'task3'), + Tudu::Task.new('doings', 'task1'), + Tudu::Task.new('doings', 'task2'), + Tudu::Task.new('doings', 'task3') ] }, { case_no: 3, case_title: 'not exists task', type: 'todos', - texts: %w{task1 task2 task3}, + texts: %w(task1 task2 task3), choose: 'task4', expected: [ - Tudu::Tasks.new('todos', 'task1'), - Tudu::Tasks.new('todos', 'task2'), - Tudu::Tasks.new('todos', 'task3'), + Tudu::Task.new('todos', 'task1'), + Tudu::Task.new('todos', 'task2'), + Tudu::Task.new('todos', 'task3') ] }, { case_no: 4, case_title: 'task exists, but dones', type: 'dones', - texts: %w{task1 task2 task3}, + texts: %w(task1 task2 task3), choose: 'task1', expected: [ - Tudu::Tasks.new('dones', 'task1'), - Tudu::Tasks.new('dones', 'task2'), - Tudu::Tasks.new('dones', 'task3'), + Tudu::Task.new('dones', 'task1'), + Tudu::Task.new('dones', 'task2'), + Tudu::Task.new('dones', 'task3') ] }, { case_no: 5, case_title: 'task exists, empty args', type: 'todos', - texts: %w{task1 task2 task3}, + texts: %w(task1 task2 task3), choose: '', expected: [ - Tudu::Tasks.new('todos', 'task2'), - Tudu::Tasks.new('todos', 'task3'), - Tudu::Tasks.new('doings', 'task1'), + Tudu::Task.new('todos', 'task2'), + Tudu::Task.new('todos', 'task3'), + Tudu::Task.new('doings', 'task1') ] }, { case_no: 6, case_title: 'task exists, nil args', type: 'todos', - texts: %w{task1 task2 task3}, + texts: %w(task1 task2 task3), choose: nil, expected: [ - Tudu::Tasks.new('todos', 'task2'), - Tudu::Tasks.new('todos', 'task3'), - Tudu::Tasks.new('doings', 'task1'), + Tudu::Task.new('todos', 'task2'), + Tudu::Task.new('todos', 'task3'), + Tudu::Task.new('doings', 'task1') ] }, { case_no: 7, case_title: 'todos not exists, empty args', type: 'doings', - texts: %w{task1 task2 task3}, + texts: %w(task1 task2 task3), choose: nil, expected: [ - Tudu::Tasks.new('doings', 'task1'), - Tudu::Tasks.new('doings', 'task2'), - Tudu::Tasks.new('doings', 'task3'), + Tudu::Task.new('doings', 'task1'), + Tudu::Task.new('doings', 'task2'), + Tudu::Task.new('doings', 'task3') ] - }, - + } ] cases.each do |c| it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do begin @@ -541,52 +542,52 @@ end def case_before(c) # implement each case before Tudu::Core.new.init - File.open("./#{Tudu::Tasks::TUDU_DIR}/#{c[:type]}", 'w') { |f|f.puts c[:texts].join("\n") } + File.open("./#{Tudu::TuduPaths::TUDU_DIR}/#{c[:type]}", 'w') { |f|f.puts c[:texts].join("\n") } end def case_after(c) # implement each case after - return unless File.exists? Tudu::Tasks::TUDU_DIR - FileUtils.rm_rf(Tudu::Tasks::TUDU_DIR) + return unless File.exist? Tudu::TuduPaths::TUDU_DIR + FileUtils.rm_rf(Tudu::TuduPaths::TUDU_DIR) end end end context :done do cases = [ { case_no: 1, case_title: 'one doing to done, shift todo to doing', - task_names: %w{task1 task2 task3}, + task_names: %w(task1 task2 task3), choose: 'task1', expected: [ - Tudu::Tasks.new('todos', 'task3'), - Tudu::Tasks.new('doings', 'task2'), - Tudu::Tasks.new('dones', 'task1'), + Tudu::Task.new('todos', 'task3'), + Tudu::Task.new('doings', 'task2'), + Tudu::Task.new('dones', 'task1') ] }, { case_no: 2, case_title: 'one doing to done, not shift todo to doing', task_names: ['task1'], choose: 'task1', expected: [ - Tudu::Tasks.new('dones', 'task1'), + Tudu::Task.new('dones', 'task1') ] }, { case_no: 3, case_title: 'no doing', task_names: ['task1'], choose: '', expected: [ - Tudu::Tasks.new('todos', 'task1'), + Tudu::Task.new('todos', 'task1') ] - }, + } ] cases.each do |c| it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do begin @@ -611,12 +612,12 @@ # implement each case before end def case_after(c) # implement each case after - return unless File.exists? Tudu::Tasks::TUDU_DIR - FileUtils.rm_rf(Tudu::Tasks::TUDU_DIR) + return unless File.exist? Tudu::TuduPaths::TUDU_DIR + FileUtils.rm_rf(Tudu::TuduPaths::TUDU_DIR) end end end context :add do @@ -626,11 +627,11 @@ case_title: 'single add', task_names1: 'task_name', task_names2: nil, task_names3: nil, expected: [ - Tudu::Tasks.new('todos', 'task_name') + Tudu::Task.new('todos', 'task_name') ] }, { case_no: 2, case_title: 'nil add', @@ -644,25 +645,25 @@ case_title: 'multi add', task_names1: 'task_name1', task_names2: 'task_name2', task_names3: 'task_name3', expected: [ - Tudu::Tasks.new('todos', 'task_name1'), - Tudu::Tasks.new('todos', 'task_name2'), - Tudu::Tasks.new('todos', 'task_name3') + Tudu::Task.new('todos', 'task_name1'), + Tudu::Task.new('todos', 'task_name2'), + Tudu::Task.new('todos', 'task_name3') ] }, { case_no: 4, case_title: 'duplicate add', task_names1: 'task_name1', task_names2: 'task_name1', task_names3: nil, expected: [ - Tudu::Tasks.new('todos', 'task_name1'), + Tudu::Task.new('todos', 'task_name1') ] - }, + } ] cases.each do |c| it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do begin @@ -673,11 +674,11 @@ # -- when -- Tudu::Tasks.add c[:task_names1], c[:task_names2], c[:task_names3] # -- then -- - actual = Tudu::Tasks.get_todos + actual = Tudu::Tasks.todos expect(actual).to eq(c[:expected]) ensure case_after c end end @@ -685,12 +686,12 @@ def case_before(c) # implement each case before end def case_after(c) - return unless File.exists? Tudu::Tasks::TUDU_DIR - FileUtils.rm_rf(Tudu::Tasks::TUDU_DIR) + return unless File.exist? Tudu::TuduPaths::TUDU_DIR + FileUtils.rm_rf(Tudu::TuduPaths::TUDU_DIR) end end end context :remove do @@ -698,26 +699,26 @@ { case_no: 1, case_title: 'single remove', add_tasks: ['task_name'], remove_tasks: ['task_name'], - expected_tasks: [], + expected_tasks: [] }, { case_no: 2, case_title: 'multi remove', - add_tasks: %w{task_name1 task_name2 task_name3}, - remove_tasks: %w{task_name1 task_name2 task_name3}, - expected_tasks: [], + add_tasks: %w(task_name1 task_name2 task_name3), + remove_tasks: %w(task_name1 task_name2 task_name3), + expected_tasks: [] }, { case_no: 3, case_title: 'not remove', add_tasks: ['task_name'], remove_tasks: ['invalid name'], - expected_tasks: [Tudu::Tasks.new('todos', 'task_name')], - }, + expected_tasks: [Tudu::Task.new('todos', 'task_name')] + } ] cases.each do |c| it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do begin @@ -741,29 +742,29 @@ def case_before(c) # implement each case before end def case_after(c) - return unless File.exists? Tudu::Tasks::TUDU_DIR - FileUtils.rm_rf(Tudu::Tasks::TUDU_DIR) + return unless File.exist? Tudu::TuduPaths::TUDU_DIR + FileUtils.rm_rf(Tudu::TuduPaths::TUDU_DIR) end end end context :filter_tasks do cases = [ { case_no: 1, case_title: 'get todos from file', tasks: [ - Tudu::Tasks.new('doings', 'task1_1'), - Tudu::Tasks.new('doings', 'task1_2'), - Tudu::Tasks.new('doings', 'task3'), + Tudu::Task.new('doings', 'task1_1'), + Tudu::Task.new('doings', 'task1_2'), + Tudu::Task.new('doings', 'task3') ], filter_word: 'task1_1', - expected: [Tudu::Tasks.new('doings', 'task1_1')], - }, + expected: [Tudu::Task.new('doings', 'task1_1')] + } ] cases.each do |c| it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do begin @@ -795,31 +796,31 @@ context :progress do cases = [ { case_no: 1, case_title: 'display progress', - todos: %w{task5 task6}, - doings: %w{task3 task4}, - dones: %w{task1 task2}, - expected: '2/6|===> |33%', + todos: %w(task5 task6), + doings: %w(task3 task4), + dones: %w(task1 task2), + expected: '2/6|===> |33%' }, { case_no: 2, case_title: 'display none progress', - todos: %w{task3 task4}, - doings: %w{task1 task2}, + todos: %w(task3 task4), + doings: %w(task1 task2), dones: [], - expected: '0/4|> |0%', + expected: '0/4|> |0%' }, { case_no: 3, case_title: 'display complete progress', todos: [], doings: [], - dones: %w{task1 task2}, - expected: '2/2|==========>|100%', - }, + dones: %w(task1 task2), + expected: '2/2|==========>|100%' + } ] cases.each do |c| it "|case_no=#{c[:case_no]}|case_title=#{c[:case_title]}" do begin @@ -839,18 +840,19 @@ end def case_before(c) # implement each case before Tudu::Core.new.init - File.open("./#{Tudu::Tasks::TUDU_DIR}/todos", 'w') { |f|f.puts c[:todos].join("\n") } - File.open("./#{Tudu::Tasks::TUDU_DIR}/doings", 'w') { |f|f.puts c[:doings].join("\n") } - File.open("./#{Tudu::Tasks::TUDU_DIR}/dones", 'w') { |f|f.puts c[:dones].join("\n") } + File.open("./#{Tudu::TuduPaths::TUDU_DIR}/todos", 'w') { |f|f.puts c[:todos].join("\n") } + File.open("./#{Tudu::TuduPaths::TUDU_DIR}/doings", 'w') { |f|f.puts c[:doings].join("\n") } + File.open("./#{Tudu::TuduPaths::TUDU_DIR}/dones", 'w') { |f|f.puts c[:dones].join("\n") } end def case_after(c) # implement each case after - return unless File.exists? Tudu::Tasks::TUDU_DIR - FileUtils.rm_rf(Tudu::Tasks::TUDU_DIR) + return unless File.exist? Tudu::TuduPaths::TUDU_DIR + FileUtils.rm_rf(Tudu::TuduPaths::TUDU_DIR) end end end end +# rubocop:enable LineLength, UnusedMethodArgument