C0 code coverage information
Generated on Mon Feb 11 21:39:28 +0100 2008 with rcov 0.8.1.2
Code reported as executed by Ruby looks like this...
and this: this line is also marked as covered.
Lines considered as run by rcov, but not reported by Ruby, look like this,
and this: these lines were inferred by rcov (using simple heuristics).
Finally, here's a line marked as not executed.
Name |
Total lines |
Lines of code |
Total coverage |
Code coverage |
spec/dst_spec.rb
|
181
|
150
|
|
|
1 $:.unshift 'lib/', File.dirname(__FILE__) + '/../lib'
2 require 'rubygems'
3 require 'spec'
4 require 'dst'
5
6 module Kernel; def puts(s); end; end
7
8 describe Dst do
9 before(:each) do
10 @dst = Dst.new
11 @task_model = Dst::Models::Task
12 @context_model = Dst::Models::Context
13 @project_model = Dst::Models::Project
14
15 @task = mock('Task', :context= => true, :project= => true, :save => true)
16 @task_model.stub!(:new).and_return(@task)
17 end
18
19 it 'should exists' do
20 @dst.should_not be_nil
21 @dst.should be_an_instance_of(Dst)
22 end
23
24 describe "when creating tasks: `<@context> <:project> task'" do
25 before(:each) do
26 @command = '@mail :proj john@doe.name about http://example.org'
27 end
28
29 describe '#process_command' do
30 it 'dispatchs command to create_task' do
31 @dst.should_receive(:create_task)
32 @dst.process_command(@command)
33 end
34
35 it 'parses description correctly' do
36 @dst.should_receive(:create_task) do |opts|
37 opts[:description].should == 'john@doe.name about http://example.org'
38 end
39 @dst.process_command(@command)
40 end
41
42 it 'parses context correctly' do
43 @dst.should_receive(:create_task) { |opts| opts[:context].should == 'mail' }
44 @dst.process_command(@command)
45 end
46
47 it 'parses project correctly' do
48 @dst.should_receive(:create_task) { |opts| opts[:project].should == 'proj' }
49 @dst.process_command(@command)
50 end
51 end
52
53 describe '#create_task' do
54 before(:each) do
55 @context = mock('Context')
56 @context_model.stub!(:find_or_create_by_name).and_return(@context)
57
58 @project = mock('Project')
59 @project_model.stub!(:find_or_create_by_name).and_return(@project)
60 end
61
62 it 'creates a new Task with given description' do
63 @task_model.should_receive(:new).with(
64 :description => 'john@doe.name about http://example.org'
65 ).and_return(@task)
66 @dst.process_command(@command)
67 end
68
69 it 'finds or creates context' do
70 @context_model.should_receive(:find_or_create_by_name).and_return(@context)
71 @dst.process_command(@command)
72 end
73
74 it "sets task's context if specified" do
75 @task.should_receive(:context=).with(@context)
76 @dst.process_command(@command)
77 end
78
79 it "doesn't set tasks's context if not specified" do
80 @task.should_not_receive(:context=)
81 @dst.process_command('task without context')
82 end
83
84 it "finds or creates project" do
85 @project_model.should_receive(:find_or_create_by_name).and_return(@project)
86 @dst.process_command(@command)
87 end
88
89 it "sets task's project if specified" do
90 @task.should_receive(:project=).with(@project)
91 @dst.process_command(@command)
92 end
93
94 it "doesn't set tasks's project if not specified" do
95 @task.should_not_receive(:project=)
96 @dst.process_command('task without project')
97 end
98
99 it 'saves new task' do
100 @task.should_receive(:save).and_return(true)
101 @dst.process_command(@command)
102 end
103
104 it 'notices that tasks have been successfuly created' do
105 @dst.should_receive(:puts).with(/ created.$/)
106 @dst.process_command(@command)
107 end
108 end
109 end
110
111 describe "when toggling a task: `^<task id>'" do
112 before(:each) do
113 @task.stub!(:status).and_return(true)
114 @task_model.stub!(:toggle!).and_return(@task)
115 end
116
117 describe '#proccess_command' do
118 it 'dispatchs to toggle_task' do
119 @dst.should_receive(:toggle_task).with(479)
120 @dst.process_command('^479')
121 end
122
123 it 'parses task id correctly' do
124 [1, 479, 0, 1087].each do |id|
125 @dst.should_receive(:toggle_task).with(id)
126 @dst.process_command("^#{id}")
127 end
128 end
129 end
130
131 describe '#toggle_task' do
132 it 'toggle task' do
133 @task_model.should_receive(:toggle!).with(3).and_return(@task)
134 @dst.process_command('^3')
135 end
136
137 it 'outputs an error message if task not found' do
138 @task_model.should_receive(:toggle!).and_raise(ActiveRecord::RecordNotFound)
139 @dst.should_receive(:puts).with("Oops, task #98 not found.")
140 @dst.process_command('^98')
141 end
142 end
143 end
144
145 describe "when listing tasks: `[<@context> <@project>] [-a]]'" do
146 before(:each) do
147 @tasks = mock('tasks', :select => [@task], :empty? => false, :map => [@task])
148 @task_model.stub!(:unfinished).and_return(@tasks)
149 end
150
151 it 'finds all unfinished tasks if no filter provided' do
152 @task_model.should_receive(:unfinished).and_return(@tasks)
153 @tasks.should_not_receive(:select)
154 @dst.process_command('')
155 end
156
157 it 'finds unfinished tasks filtered by context' do
158 @task_model.should_receive(:unfinished).and_return(@tasks)
159 @tasks.should_receive(:select)
160 @dst.process_command('@context')
161 end
162
163 it 'finds unfinished tasks filtered by project' do
164 @task_model.should_receive(:unfinished).and_return(@tasks)
165 @tasks.should_receive(:select)
166 @dst.process_command(':project')
167 end
168
169 it 'outputs tasks' do
170 @tasks.should_receive(:map).and_return(@tasks)
171 @tasks.should_receive(:join).and_return("")
172 @dst.process_command('')
173 end
174
175 it 'notices if no tasks found' do
176 @tasks.should_receive(:empty?).and_return(true)
177 @dst.should_receive(:puts).with('No tasks found')
178 @dst.process_command('')
179 end
180 end
181 end
Generated using the rcov code coverage analysis tool for Ruby version 0.8.1.2.