dayrb 2.0.2
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.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/LICENSE +8 -0
- data/Rakefile +118 -0
- data/VERSION +1 -0
- data/bin/day.rb +144 -0
- data/changelog.md +100 -0
- data/dayrb.gemspec +14 -0
- data/lib/day/configuration.rb +140 -0
- data/lib/day/parser.rb +168 -0
- data/lib/day/presenter.rb +223 -0
- data/lib/day/task.rb +44 -0
- data/lib/day/tasklist.rb +44 -0
- data/readme.md +53 -0
- data/spec/configuration_spec.rb +142 -0
- data/spec/parser_spec.rb +191 -0
- data/spec/spec_helper.rb +35 -0
- metadata +64 -0
data/spec/parser_spec.rb
ADDED
@@ -0,0 +1,191 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Parser do
|
4
|
+
|
5
|
+
describe "#parse_options" do
|
6
|
+
|
7
|
+
before :each do
|
8
|
+
bootstrap
|
9
|
+
end
|
10
|
+
|
11
|
+
context "for the print command" do
|
12
|
+
it "should print on nil command" do
|
13
|
+
ARGV = []
|
14
|
+
expect(Parser.parse_options(@config)).to eq({:operation => :print})
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should optionally accept -a for 'all'" do
|
18
|
+
ARGV = ["-a"]
|
19
|
+
expect(Parser.parse_options(@config)).to eq({:operation => :print, :all => true})
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
context "for the clear command" do
|
24
|
+
it "should set :clear command" do
|
25
|
+
ARGV = ["clear"]
|
26
|
+
expect(Parser.parse_options(@config)).to eq({:operation => :clear})
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should optionally accept a specific alpha task" do
|
30
|
+
ARGV = ["clear", "test"]
|
31
|
+
expect(Parser.parse_options(@config)).to eq({:operation => :clear, :task => "test"})
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should optionally accept a specific numeric task" do
|
35
|
+
ARGV = ["clear", "0"]
|
36
|
+
expect(Parser.parse_options(@config)).to eq({:operation => :clear, :task => "test"})
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should reject an alpha non-task" do
|
40
|
+
ARGV = ["clear", "not_a_task"]
|
41
|
+
expect {Parser.parse_options(@config)}.to raise_error(ArgumentError)
|
42
|
+
end
|
43
|
+
|
44
|
+
it "should reject a numeric non-task" do
|
45
|
+
ARGV = ["clear", "4"]
|
46
|
+
expect {Parser.parse_options(@config)}.to raise_error(ArgumentError)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
context "for the delete command" do
|
51
|
+
it "should set command to delete" do
|
52
|
+
ARGV = ["delete", "test"]
|
53
|
+
expect(Parser.parse_options(@config)).to eq({:operation => :delete, :task => "test"})
|
54
|
+
end
|
55
|
+
|
56
|
+
it "should demand a second argument" do
|
57
|
+
ARGV = ["delete"]
|
58
|
+
expect {Parser.parse_options(@config)}.to raise_error(ArgumentError)
|
59
|
+
end
|
60
|
+
|
61
|
+
it "should reject a non-task alpha value" do
|
62
|
+
ARGV = ["delete", "not_a_task"]
|
63
|
+
expect {Parser.parse_options(@config)}.to raise_error(ArgumentError)
|
64
|
+
end
|
65
|
+
|
66
|
+
it "should reject a out-of-bounds numeric value" do
|
67
|
+
ARGV = ["delete", "5"]
|
68
|
+
expect {Parser.parse_options(@config)}.to raise_error(ArgumentError)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
context "for the info command" do
|
73
|
+
it "should set command as :info" do
|
74
|
+
ARGV = ["info"]
|
75
|
+
expect(Parser.parse_options(@config)).to eq({:operation => :print_info})
|
76
|
+
end
|
77
|
+
|
78
|
+
it "should also accept a specific task" do
|
79
|
+
ARGV = ["info", "test"]
|
80
|
+
expect(Parser.parse_options(@config)).to eq({:operation => :print_info, :task => "test"})
|
81
|
+
end
|
82
|
+
|
83
|
+
it "should raise if task doesn't exist" do
|
84
|
+
ARGV = ["info", "not_a_task"]
|
85
|
+
expect {Parser.parse_options(@config)}.to raise_error(ArgumentError)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
context "for the help command" do
|
90
|
+
it "should set command as :help on 'help'" do
|
91
|
+
ARGV = ["help"]
|
92
|
+
expect(Parser.parse_options(@config)).to eq({:operation => :print_help})
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
context "for the version command" do
|
97
|
+
it "should set command as :version on 'version'" do
|
98
|
+
ARGV = ["version"]
|
99
|
+
expect(Parser.parse_options(@config)).to eq({:operation => :print_version})
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
context "for the switch command" do
|
104
|
+
it "should set :switch command" do
|
105
|
+
ARGV = ["test"]
|
106
|
+
expect(Parser.parse_options(@config)).to eq({:operation => :switch, :task => "test"})
|
107
|
+
end
|
108
|
+
|
109
|
+
it "should also accept numeric tasks" do
|
110
|
+
ARGV = ["0"]
|
111
|
+
expect(Parser.parse_options(@config)).to eq({:operation => :switch, :task => "test"})
|
112
|
+
end
|
113
|
+
|
114
|
+
it "should raise if numeric task if out of bounds" do
|
115
|
+
ARGV = ["4"]
|
116
|
+
expect {Parser.parse_options(@config)}.to raise_error(ArgumentError)
|
117
|
+
end
|
118
|
+
|
119
|
+
it "should accept alpha tasks" do
|
120
|
+
ARGV = ["test"]
|
121
|
+
expect(Parser.parse_options(@config)).to eq({:operation => :switch, :task => "test"})
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
context "for the new command" do
|
126
|
+
EDITOR = 'vim'
|
127
|
+
|
128
|
+
before :each do
|
129
|
+
bootstrap
|
130
|
+
end
|
131
|
+
|
132
|
+
it "should set :new command" do
|
133
|
+
ARGV = ["test2"]
|
134
|
+
expect(Parser.parse_options(@config)).to eq({:operation => :new, :task => "test2"})
|
135
|
+
end
|
136
|
+
|
137
|
+
it "should accept a time estimate" do
|
138
|
+
ARGV = ["test2", "25"]
|
139
|
+
expect(Parser.parse_options(@config)).to eq({:operation => :new, :task => "test2",
|
140
|
+
:estimate => 1500})
|
141
|
+
end
|
142
|
+
|
143
|
+
it "should reject a second time estimate" do
|
144
|
+
ARGV = ["test2", "25", "34"]
|
145
|
+
expect {Parser.parse_options(@config)}.to raise_error(ArgumentError)
|
146
|
+
end
|
147
|
+
|
148
|
+
# The three tests that include EDITOR flag are commented out because they require
|
149
|
+
# manual interactions to run (until I figure out how to circumvent that of course)
|
150
|
+
# and are cumbersome to the testing cycle.
|
151
|
+
|
152
|
+
# # Test 1 of EDITOR: save file with text 'test'
|
153
|
+
# it "should capture the description from EDITOR flag" do
|
154
|
+
# ARGV = ["test2", EDITOR]
|
155
|
+
# expect(Parser.parse_options(@config)).to eq({:operation => :new, :task => "test2",
|
156
|
+
# :description => "test", :editor => true})
|
157
|
+
# end
|
158
|
+
|
159
|
+
# # Test 2 of EDITOR: just quit vim
|
160
|
+
# it "should raise error if we got no description from EDITOR" do
|
161
|
+
# ARGV = ["test2", EDITOR]
|
162
|
+
# expect {Parser.parse_options(@config)}.to raise_error(ArgumentError)
|
163
|
+
# end
|
164
|
+
|
165
|
+
it "should accept valid days of the week" do
|
166
|
+
ARGV = ["test2", "m", "w"]
|
167
|
+
expect(Parser.parse_options(@config)).to eq({:operation => :new, :task => "test2",
|
168
|
+
:days => [:monday, :wednesday]})
|
169
|
+
end
|
170
|
+
|
171
|
+
# # Test 3 of EDITOR: Save file with text 'test'
|
172
|
+
# it "should accept multiple options in arbitrary order" do
|
173
|
+
# ARGV = ["test2", EDITOR, "m", "25", "f"]
|
174
|
+
# expect(Parser.parse_options(@config)).to eq({:operation => :new, :task => "test2",
|
175
|
+
# :days => [:monday, :friday], :estimate => 1500, :description => "test",
|
176
|
+
# :editor => true})
|
177
|
+
# end
|
178
|
+
end
|
179
|
+
|
180
|
+
context "for the leave command" do
|
181
|
+
before :each do
|
182
|
+
bootstrap_with_context
|
183
|
+
end
|
184
|
+
|
185
|
+
it "should set :leave command on repeated context" do
|
186
|
+
ARGV = ["test"]
|
187
|
+
expect(Parser.parse_options(@config)).to eq({:operation => :leave})
|
188
|
+
end
|
189
|
+
end
|
190
|
+
end
|
191
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
require_relative '../lib/configuration'
|
2
|
+
require_relative '../lib/parser'
|
3
|
+
|
4
|
+
FILE_PATH = 'test_db'
|
5
|
+
FULL_FILE_PATH = "#{FILE_PATH}.dir"
|
6
|
+
|
7
|
+
$VERBOSE = nil
|
8
|
+
|
9
|
+
def bootstrap
|
10
|
+
@db = YAML::DBM.new(FILE_PATH)
|
11
|
+
@db.clear
|
12
|
+
@config = Configuration.new(@db)
|
13
|
+
bootstrap_task("test")
|
14
|
+
end
|
15
|
+
|
16
|
+
def bootstrap_task(name)
|
17
|
+
@config.new_task({:task => name})
|
18
|
+
@config.reload
|
19
|
+
end
|
20
|
+
|
21
|
+
def bootstrap_with_context
|
22
|
+
bootstrap
|
23
|
+
@config.switch_to("test")
|
24
|
+
@config.save
|
25
|
+
end
|
26
|
+
|
27
|
+
class String
|
28
|
+
def nan?
|
29
|
+
self !~ /^\s*[+-]?((\d+_?)*\d+(\.(\d+_?)*\d+)?|\.(\d+_?)*\d+)(\s*|([eE][+-]?(\d+_?)*\d+)\s*)$/
|
30
|
+
end
|
31
|
+
|
32
|
+
def number?
|
33
|
+
!self.nan?
|
34
|
+
end
|
35
|
+
end
|
metadata
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: dayrb
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 2.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Cameron Carroll
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-08-17 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Create and track time on tasks via command-line.
|
14
|
+
email: ckcarroll4@gmail.com
|
15
|
+
executables:
|
16
|
+
- day.rb
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- ".gitignore"
|
21
|
+
- LICENSE
|
22
|
+
- Rakefile
|
23
|
+
- VERSION
|
24
|
+
- bin/day.rb
|
25
|
+
- changelog.md
|
26
|
+
- dayrb.gemspec
|
27
|
+
- lib/day/configuration.rb
|
28
|
+
- lib/day/parser.rb
|
29
|
+
- lib/day/presenter.rb
|
30
|
+
- lib/day/task.rb
|
31
|
+
- lib/day/tasklist.rb
|
32
|
+
- readme.md
|
33
|
+
- spec/configuration_spec.rb
|
34
|
+
- spec/parser_spec.rb
|
35
|
+
- spec/spec_helper.rb
|
36
|
+
homepage: http://github.com/sanarothe/day
|
37
|
+
licenses:
|
38
|
+
- MIT
|
39
|
+
metadata: {}
|
40
|
+
post_install_message:
|
41
|
+
rdoc_options: []
|
42
|
+
require_paths:
|
43
|
+
- lib
|
44
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ">="
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
49
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
requirements: []
|
55
|
+
rubyforge_project:
|
56
|
+
rubygems_version: 2.2.2
|
57
|
+
signing_key:
|
58
|
+
specification_version: 4
|
59
|
+
summary: To-do & Time-Tracking CLI App
|
60
|
+
test_files:
|
61
|
+
- spec/configuration_spec.rb
|
62
|
+
- spec/parser_spec.rb
|
63
|
+
- spec/spec_helper.rb
|
64
|
+
has_rdoc:
|