Browse files

Added pending specs to list. Refactored Task#to_row.

Adde spec helper for formatting tasks
  • Loading branch information...
1 parent 147de8a commit c3583dcb1017ea100d41163f05ea78d83b6745f6 @pepe pepe committed Nov 15, 2010
Showing with 70 additions and 14 deletions.
  1. +5 −5 lib/dooby/list.rb
  2. +4 −1 lib/dooby/task.rb
  3. +42 −6 spec/list_spec.rb
  4. +10 −1 spec/spec_helper.rb
  5. +9 −1 spec/task_spec.rb
View
10 lib/dooby/list.rb
@@ -59,7 +59,7 @@ def tasks
@tasks.dup
end
- def find (what_to_show=[])
+ def find(what_to_show=[])
list = []
if @tasks.empty?
@@ -78,14 +78,14 @@ def find (what_to_show=[])
to_add << task_with_today_tag
to_delete << id
else
- list << TASK_ROW_TEMPLATE.call(task)
+ list << task.to_row
end
end
to_delete.each { |task_id| delete!(task_id) }
to_add.each do |task|
add task
- list << TASK_ROW_TEMPLATE.call(task)
+ list << task.to_row
end
when *SPECIAL_CHARS then
@@ -104,7 +104,7 @@ def find (what_to_show=[])
end
@tasks.each do |id, task|
if what_to_show.all? { |term| task.todo.include? term }
- list << TASK_ROW_TEMPLATE.call(task)
+ list << task.to_row
end
end
@@ -162,4 +162,4 @@ def load!
end
-end
+end
View
5 lib/dooby/task.rb
@@ -27,7 +27,10 @@ def colorize
color = SPECIAL_CHAR_COLORS[todo.first_char]
todo.send color
end
-
end
+
+ def to_row
+ TASK_ROW_TEMPLATE.call(self)
+ end
end
end
View
48 spec/list_spec.rb
@@ -138,25 +138,61 @@ module Dooby
describe '#find' do
describe 'with empty array as argument' do
- it 'should return a list of all the items'
+ it 'should return a list of all the items' do
+ YAML.stub(:load_file).and_return fake_tasks
+ list = List.new @location
+
+ list.find([]).should == formatted(list)
+ end
end
describe 'with special tags as argument' do
- it 'should return only the specified tags'
+ it 'returns one by specified tag' do
+ YAML.stub(:load_file).and_return fake_tasks
+ list = List.new @location
+ list.add(task = Task.new('@leader #context :status'))
+
+ list.find(['@leader']).should == [task.to_row]
+ end
+ it 'should return many by the specified tags' do
+ YAML.stub(:load_file).and_return fake_tasks
+ list = List.new @location
+
+ list.find(['@person']).should == formatted(list)
+ end
end
describe 'with an array of terms as argument' do
- it 'should return only the items containing all the specified tags'
+ it 'should return only the items containing all the specified tags' do
+ YAML.stub(:load_file).and_return fake_tasks
+ list = List.new @location
+ list.add(task = Task.new('@leader #context :status'))
+ list.add(task_two = Task.new('@leader #context :done'))
+
+ list.find(['#context', '@leader']).should == formatted([task, task_two])
+ end
end
end
describe '#all_tags' do
- it 'should return only the tags of all the items'
+ it 'should return the tags of all the items' do
+ YAML.stub(:load_file).and_return fake_tasks
+ list = List.new @location
+
+ #NOTE shouldn't this array be of uniq tags?
+ list.all_tags.should == ["#context", "@person", "%project", ":status0", "#context", "@person", "%project", ":status1", "#context", "@person", "%project", ":status2"]
+ end
end
describe '#current_item' do
- it 'should return the item tagged with :doing'
+ it 'should return the item tagged with :doing' do
+ YAML.stub(:load_file).and_return fake_tasks
+ list = List.new @location
+ list.add(Task.new('@leader #context :status :doing'))
+
+ list.current_item.should == "@leader #context :status"
+ end
end
end
end
-end
+end
View
11 spec/spec_helper.rb
@@ -19,4 +19,13 @@ def fake_tasks
tasks[task.id] = task
end
tasks
-end
+end
+
+# returns tasks list formated for console
+def formatted(tasks)
+ if tasks.is_a? Array
+ tasks.map {|task| task.to_row}
+ else
+ tasks.tasks.map {|id,task| task.to_row}
+ end
+end
View
10 spec/task_spec.rb
@@ -46,6 +46,14 @@ module Dooby
task.todo.should == todo
end
end
+
+ describe "#to_row" do
+ it "returns representation in row for console printing" do
+ task = Task.new "#context @person %project :status"
+ task.to_row.should == " (\e[31m#{task.id}\e[0m) \e[33m#context\e[0m \e[34m@person\e[0m \e[37m%project\e[0m \e[35m:status\e[0m"
+
+ end
+ end
end
-end
+end

0 comments on commit c3583dc

Please sign in to comment.