r2do 0.0.6

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.
@@ -0,0 +1,211 @@
1
+ #
2
+ # Copyright 2012 Christian Giacomi http://www.christiangiacomi.com
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ require 'spec_helper'
18
+
19
+ module R2do
20
+
21
+ describe Category do
22
+
23
+ before :each do
24
+ @category = Category.new("A category")
25
+ end
26
+
27
+ describe "#new" do
28
+ context "with a name" do
29
+ it "returns a Category object" do
30
+ @category.should be_an_instance_of Category
31
+ end
32
+
33
+ it "contains no tasks" do
34
+ @category.should have(0).tasks
35
+ end
36
+
37
+ it "contains the correct name" do
38
+ @category.name.should eql "A category"
39
+ end
40
+ end
41
+
42
+ context "without a name" do
43
+ it "raises an error" do
44
+ expect{ Category.new }.to raise_error(ArgumentError)
45
+ end
46
+ end
47
+ end
48
+
49
+ describe "#add" do
50
+ context "a nil task" do
51
+ it "raises and error" do
52
+ expect{ @category.add(nil) }.to raise_error(ArgumentError)
53
+ end
54
+ end
55
+
56
+ context "in empty category" do
57
+ it "has one task" do
58
+ task = Task.new("task")
59
+ @category.add(task)
60
+ @category.should have(1).tasks
61
+ end
62
+ end
63
+
64
+ context "in a category with one task" do
65
+ it "has two tasks" do
66
+ @category.add(Task.new("task 1"))
67
+ @category.should have(1).tasks
68
+
69
+ @category.add(Task.new("task 2"))
70
+ @category.should have(2).tasks
71
+ end
72
+ end
73
+
74
+ context "add duplicate task" do
75
+ it "raises an exception" do
76
+ description = "Sample task"
77
+
78
+ @category.add(Task.new(description))
79
+ expect{ @category.add(Task.new(description)) }.to raise_error(TaskAlreadyExistsError)
80
+ end
81
+ end
82
+ end
83
+
84
+ describe "#remove" do
85
+ context "in empty category" do
86
+ it "raises an error" do
87
+ expect{ @category.remove(Task.new("Sample Task")) }.to raise_error(TaskNotFoundError)
88
+ end
89
+ end
90
+
91
+ context "on a category that doesn't contain the task" do
92
+ it "raises an error" do
93
+ @category.add(Task.new("My Task"))
94
+ expect{ @category.remove(Task.new("Task to remove")) }.to raise_error(TaskNotFoundError)
95
+ end
96
+ end
97
+
98
+ context "on the correct category" do
99
+ it "returns the task" do
100
+ task = Task.new("My Task")
101
+ @category.add(task)
102
+ removed_task = @category.remove(task)
103
+ removed_task.should eql task
104
+ end
105
+
106
+ it "has a task less" do
107
+ task = Task.new("My Task")
108
+ @category.add(task)
109
+ @category.should have(1).tasks
110
+
111
+ removed_task = @category.remove(task)
112
+ @category.should have(0).tasks
113
+ end
114
+ end
115
+ end
116
+
117
+ describe "#to_s" do
118
+ context "with one task" do
119
+ it "returns a description of the task" do
120
+ result = StringIO.new
121
+
122
+ result << "#{@category.name}:\n\n"
123
+ result << " %-30s %s\n" % ["Task", "Completed"]
124
+ result << " " << "-"*51
125
+ result << "\n"
126
+ result << " [ ] %-30s \n" % ["Sample task"]
127
+
128
+
129
+ @category.add(Task.new("Sample task"))
130
+ @category.to_s.should eql result.string
131
+ end
132
+ end
133
+
134
+ context "with two tasks" do
135
+ it "returns the correct description of the tasks" do
136
+ result = StringIO.new
137
+
138
+ result << "#{@category.name}:\n\n"
139
+ result << " %-30s %s\n" % ["Task", "Completed"]
140
+ result << " " << "-"*51
141
+ result << "\n"
142
+ result << " [ ] %-30s \n" % "First task"
143
+ result << " [ ] %-30s \n" % "Second task"
144
+
145
+ @category.add(Task.new("First task"))
146
+ @category.add(Task.new("Second task"))
147
+ @category.to_s.should eql result.string
148
+ end
149
+ end
150
+ end
151
+
152
+ describe "#find_by_description" do
153
+ context "with no tasks" do
154
+ it "returns nil" do
155
+ task = @category.find_by_description('Sample Task')
156
+ task.should eql nil
157
+ end
158
+ end
159
+
160
+ context "with tasks" do
161
+ it "returns nil if you provide the wrong desctiption" do
162
+ @category.add(Task.new("Sample task"))
163
+ task = @category.find_by_description("A non existent task")
164
+ task.should eql nil
165
+ end
166
+
167
+ it "returns the task if it exists" do
168
+ description = "Sample task"
169
+ a_task = Task.new(description)
170
+ @category.add(a_task)
171
+ return_task = @category.find_by_description(description)
172
+ return_task.should eql a_task
173
+ end
174
+
175
+ it "returns the task if it exists and there are multiple tasks" do
176
+ description1 = "Sample task1"
177
+ description2 = "Sample task2"
178
+
179
+ task1 = Task.new(description1)
180
+ task2 = Task.new(description2)
181
+
182
+ @category.add(task1)
183
+ @category.add(task2)
184
+
185
+ return_task = @category.find_by_description(description2)
186
+ return_task.should eql task2
187
+ end
188
+ end
189
+ end
190
+
191
+ describe "#set_current" do
192
+ it "returns the correct task" do
193
+ task = Task.new("Sample Task")
194
+ @category.set_current(task)
195
+ @category.current_task.should eql task
196
+ end
197
+ end
198
+
199
+ describe "#clear_current_task" do
200
+ it "should return nil" do
201
+ task = Task.new("Sample Task")
202
+ @category.set_current(task)
203
+ @category.current_task.should eql task
204
+
205
+ @category.clear_current_task()
206
+ @category.current_task.should eql nil
207
+ end
208
+ end
209
+ end
210
+
211
+ end
@@ -0,0 +1,85 @@
1
+ #
2
+ # Copyright 2012 Christian Giacomi http://www.christiangiacomi.com
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ require 'spec_helper'
18
+
19
+ module R2do
20
+
21
+ describe Command do
22
+ before(:each) do
23
+ @callback_invoked = false
24
+ end
25
+
26
+ def callback(args)
27
+ @callback_invoked = true
28
+ end
29
+
30
+ describe "#new" do
31
+ context "valid arguments" do
32
+ it "returns an instance of Command" do
33
+ command = Command.new('c', 'category', nil, 'description for this command', method(:callback))
34
+ command.should be_an_instance_of Command
35
+ end
36
+ end
37
+
38
+ context "null args" do
39
+ it "raises an error if the swtich is null" do
40
+ expect{ Command.new(nil, 'category', nil, 'description for this command', method(:callback)) }.to raise_error(ArgumentError)
41
+ end
42
+
43
+ it "raises an error if the name is null" do
44
+ expect{ Command.new('c', nil, nil, 'description for this command', method(:callback)) }.to raise_error(ArgumentError)
45
+ end
46
+
47
+ it "raises an error if the description is null" do
48
+ expect{ Command.new('c', 'category', nil, nil, method(:callback)) }.to raise_error(ArgumentError)
49
+ end
50
+
51
+ it "raises an error if the callback is null" do
52
+ expect{ Command.new('c', 'category', nil, 'desctiption', nil) }.to raise_error(ArgumentError)
53
+ end
54
+ end
55
+ end
56
+
57
+ describe "#to_s" do
58
+ it "returns the correct representation" do
59
+ short = 'c'
60
+ extended = 'category'
61
+ description = 'description for this command'
62
+
63
+ result = "%2s, %-10s \t# %s" % [short, extended, description]
64
+ command = Command.new(short, extended, nil, description, method(:callback))
65
+ command.to_s.should eql result
66
+ end
67
+ end
68
+
69
+ describe "#execute" do
70
+ it "exectutes the callback" do
71
+ @callback_invoked.should eql false
72
+
73
+ short = 'c'
74
+ extended = 'category'
75
+ description = 'description for this command'
76
+ args = Array.new
77
+ command = Command.new(short, extended, nil, description, method(:callback))
78
+ command.execute(args)
79
+
80
+ @callback_invoked.should eql true
81
+ end
82
+ end
83
+ end
84
+
85
+ end
@@ -0,0 +1,54 @@
1
+ #
2
+ # Copyright 2012 Christian Giacomi http://www.christiangiacomi.com
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ require 'spec_helper'
18
+
19
+ module R2do
20
+
21
+ describe State do
22
+
23
+ before :each do
24
+ @state = State.new()
25
+ end
26
+
27
+ describe "#new" do
28
+ context "default constructor" do
29
+ it "returns a State object" do
30
+ @state.should be_an_instance_of State
31
+ end
32
+
33
+ it "contains no Categories" do
34
+ @state.should have(0).categories
35
+ end
36
+
37
+ it "has no selected category" do
38
+ @state.current_category.should eql nil
39
+ end
40
+ end
41
+ end
42
+
43
+ describe "#add" do
44
+ context "adding one category" do
45
+ it "contains one category" do
46
+ @state.add(Category.new("A sample category"))
47
+ @state.should have(1).categories
48
+ end
49
+ end
50
+ end
51
+
52
+ end
53
+
54
+ end
@@ -0,0 +1,22 @@
1
+ #
2
+ # Copyright 2012 Christian Giacomi http://www.christiangiacomi.com
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ # require 'spec_helper'
18
+
19
+ # module R2do
20
+
21
+
22
+ # end
@@ -0,0 +1,102 @@
1
+ #
2
+ # Copyright 2012 Christian Giacomi http://www.christiangiacomi.com
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ require 'spec_helper'
18
+
19
+ module R2do
20
+
21
+ describe Task do
22
+
23
+ before :each do
24
+ @task = Task.new("Task to complete")
25
+ end
26
+
27
+ describe "#new" do
28
+ context "with a description" do
29
+ it "returns a Task object" do
30
+ @task.should be_an_instance_of Task
31
+ end
32
+ end
33
+
34
+ context "without a description" do
35
+ it "raises an error" do
36
+ expect { Task.new }.to raise_error(ArgumentError)
37
+ end
38
+ end
39
+ end
40
+
41
+ describe "#description" do
42
+ it "returns the correct description" do
43
+ @task.description.should eql "Task to complete"
44
+ end
45
+ end
46
+
47
+ describe "#to_s" do
48
+ context "on a task that is not completed" do
49
+ it "returns the correct to string representation" do
50
+ result = "[ ] %-30s " % ["Task to complete"]
51
+ @task.to_s.should eql result
52
+ end
53
+ end
54
+
55
+ context "on a task that is complete" do
56
+ it "returns the correct to string representation" do
57
+ date = DateTime.now.strftime('%a %b %e, %Y')
58
+ result = "[x] %-30s %s" % ["Task to complete", date]
59
+ @task.completed()
60
+ @task.to_s.should eql result
61
+ end
62
+ end
63
+ end
64
+
65
+ describe "#done" do
66
+ context "by default" do
67
+ it "returns false" do
68
+ @task.done?.should eql false
69
+ end
70
+ end
71
+
72
+ context "when a task is completed" do
73
+ it "returns true" do
74
+ @task.completed()
75
+ @task.done?.should eql true
76
+ end
77
+ end
78
+ end
79
+
80
+ describe "#date_done" do
81
+ context "when a task is not completed" do
82
+ it "returns nil" do
83
+ @task.date_done().should eql nil
84
+ end
85
+ end
86
+
87
+ context "when a task is completed" do
88
+ it "returns the correct date" do
89
+ @task.completed()
90
+ @task.date_done().strftime("%F").should eql DateTime.now().strftime("%F")
91
+ end
92
+
93
+ # it "cannot be modified" do
94
+ # @task.completed()
95
+ # expect { @task.date_done = DateTime.now }.to raise_error(NoMethodError)
96
+ # end
97
+ end
98
+ end
99
+
100
+ end
101
+
102
+ end
@@ -0,0 +1,20 @@
1
+ #
2
+ # Copyright 2012 Christian Giacomi http://www.christiangiacomi.com
3
+ #
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
15
+ #
16
+
17
+ require 'simplecov'
18
+ SimpleCov.start
19
+
20
+ require 'r2do'
metadata ADDED
@@ -0,0 +1,167 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: r2do
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.6
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - cgiacomi
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-07-22 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: yard
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: simplecov
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: redcarpet
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ description: A simple todo gem
95
+ email:
96
+ - christiangiacomi@gmail.com
97
+ executables:
98
+ - r2do
99
+ extensions: []
100
+ extra_rdoc_files: []
101
+ files:
102
+ - .gitignore
103
+ - .travis.yml
104
+ - Gemfile
105
+ - LICENSE
106
+ - README.md
107
+ - Rakefile
108
+ - bin/r2do
109
+ - lib/r2do.rb
110
+ - lib/r2do/category.rb
111
+ - lib/r2do/command.rb
112
+ - lib/r2do/exceptions.rb
113
+ - lib/r2do/handlers/handle_categories.rb
114
+ - lib/r2do/handlers/handle_category.rb
115
+ - lib/r2do/handlers/handle_current.rb
116
+ - lib/r2do/handlers/handle_init.rb
117
+ - lib/r2do/handlers/handle_task.rb
118
+ - lib/r2do/state.rb
119
+ - lib/r2do/task.rb
120
+ - lib/r2do/ui.rb
121
+ - lib/r2do/utility.rb
122
+ - lib/r2do/version.rb
123
+ - r2do.gemspec
124
+ - spec/r2do/category_spec.rb
125
+ - spec/r2do/command_spec.rb
126
+ - spec/r2do/controller_spec.rb
127
+ - spec/r2do/r2do_spec.rb
128
+ - spec/r2do/task_spec.rb
129
+ - spec/spec_helper.rb
130
+ homepage: ''
131
+ licenses: []
132
+ post_install_message:
133
+ rdoc_options: []
134
+ require_paths:
135
+ - lib
136
+ required_ruby_version: !ruby/object:Gem::Requirement
137
+ none: false
138
+ requirements:
139
+ - - ! '>='
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
142
+ segments:
143
+ - 0
144
+ hash: -3996115367842685634
145
+ required_rubygems_version: !ruby/object:Gem::Requirement
146
+ none: false
147
+ requirements:
148
+ - - ! '>='
149
+ - !ruby/object:Gem::Version
150
+ version: '0'
151
+ segments:
152
+ - 0
153
+ hash: -3996115367842685634
154
+ requirements: []
155
+ rubyforge_project:
156
+ rubygems_version: 1.8.24
157
+ signing_key:
158
+ specification_version: 3
159
+ summary: A simple todo gem
160
+ test_files:
161
+ - spec/r2do/category_spec.rb
162
+ - spec/r2do/command_spec.rb
163
+ - spec/r2do/controller_spec.rb
164
+ - spec/r2do/r2do_spec.rb
165
+ - spec/r2do/task_spec.rb
166
+ - spec/spec_helper.rb
167
+ has_rdoc: