Overbryd-mighty-mite 0.1.0
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.
- data/.gitignore +5 -0
- data/LICENSE +20 -0
- data/README.textile +156 -0
- data/Rakefile +23 -0
- data/TODO +4 -0
- data/VERSION +1 -0
- data/bin/mite +13 -0
- data/lib/mighty_mite/application.rb +169 -0
- data/lib/mighty_mite/autocomplete.rb +48 -0
- data/lib/mighty_mite.rb +34 -0
- data/lib/mite_ext.rb +53 -0
- data/lib/string_ext.rb +50 -0
- data/mighty-mite.gemspec +76 -0
- data/spec/spec_helper.rb +9 -0
- data/spec/unit/mighty_mite/application_spec.rb +509 -0
- data/spec/unit/mighty_mite/autocomplete_spec.rb +100 -0
- data/spec/unit/mighty_mite_spec.rb +51 -0
- data/spec/unit/mite_ext_spec.rb +99 -0
- data/spec/unit/string_ext_spec.rb +67 -0
- data/vendor/yolk-mite-rb-0.0.3/CHANGES.txt +11 -0
- data/vendor/yolk-mite-rb-0.0.3/LICENSE +20 -0
- data/vendor/yolk-mite-rb-0.0.3/README.textile +70 -0
- data/vendor/yolk-mite-rb-0.0.3/Rakefile +24 -0
- data/vendor/yolk-mite-rb-0.0.3/VERSION.yml +4 -0
- data/vendor/yolk-mite-rb-0.0.3/lib/mite/customer.rb +9 -0
- data/vendor/yolk-mite-rb-0.0.3/lib/mite/project.rb +16 -0
- data/vendor/yolk-mite-rb-0.0.3/lib/mite/service.rb +7 -0
- data/vendor/yolk-mite-rb-0.0.3/lib/mite/time_entry.rb +54 -0
- data/vendor/yolk-mite-rb-0.0.3/lib/mite/time_entry_group.rb +36 -0
- data/vendor/yolk-mite-rb-0.0.3/lib/mite/tracker.rb +34 -0
- data/vendor/yolk-mite-rb-0.0.3/lib/mite/user.rb +19 -0
- data/vendor/yolk-mite-rb-0.0.3/lib/mite-rb.rb +105 -0
- metadata +90 -0
@@ -0,0 +1,509 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../../spec_helper'
|
2
|
+
|
3
|
+
describe MightyMite::Application, 'new' do
|
4
|
+
it "should load the configuration for MightyMite" do
|
5
|
+
MightyMite.should_receive(:load_configuration)
|
6
|
+
MightyMite::Application.new []
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should not load the configuration if the first argument is 'configure'" do
|
10
|
+
MightyMite.should_not_receive(:load_configuration)
|
11
|
+
MightyMite::Application.new ['configure']
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should set arguments" do
|
15
|
+
MightyMite.stub!(:load_configuration)
|
16
|
+
MightyMite::Application.new(['1', '2', '3']).instance_variable_get('@arguments').should == ['1', '2', '3']
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe MightyMite::Application, 'run' do
|
21
|
+
before(:each) do
|
22
|
+
MightyMite.stub!(:load_configuration)
|
23
|
+
end
|
24
|
+
|
25
|
+
describe 'no argument' do
|
26
|
+
before(:each) do
|
27
|
+
@application = MightyMite::Application.new []
|
28
|
+
@application.stub!(:say)
|
29
|
+
@application.stub!(:flirt).and_return 'Your beautiful eyes touch my heart.'
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should tell the inspection of the current tracker if there is one" do
|
33
|
+
tracker = stub('tracker', :inspect => 'I am the inspection of this tracker')
|
34
|
+
Mite::Tracker.stub!(:current).and_return tracker
|
35
|
+
@application.should_receive(:tell).with 'I am the inspection of this tracker'
|
36
|
+
@application.run
|
37
|
+
end
|
38
|
+
|
39
|
+
it "should tell something romantic if there is no current tracker" do
|
40
|
+
Mite::Tracker.stub!(:current).and_return nil
|
41
|
+
@application.should_receive(:tell).with 'Your beautiful eyes touch my heart.'
|
42
|
+
@application.run
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
describe 'the open argument' do
|
47
|
+
it "should try to open the account url or at least echo it" do
|
48
|
+
Mite.stub!(:account_url).and_return 'http://demo.mite.yo.lk'
|
49
|
+
application = MightyMite::Application.new ['open']
|
50
|
+
application.should_receive(:exec).with "open 'http://demo.mite.yo.lk' || echo 'http://demo.mite.yo.lk'"
|
51
|
+
application.run
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
describe 'the help argument' do
|
56
|
+
it "should try to open the github repository of mighty mite or at least echo it" do
|
57
|
+
application = MightyMite::Application.new ['help']
|
58
|
+
application.should_receive(:exec).with "open 'http://github.com/Overbryd/mighty-mite' || echo 'http://github.com/Overbryd/mighty-mite'"
|
59
|
+
application.run
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
describe 'the configure argument' do
|
64
|
+
before(:each) do
|
65
|
+
@application = MightyMite::Application.new ['configure', 'demo', '123']
|
66
|
+
@application.stub!(:tell)
|
67
|
+
end
|
68
|
+
|
69
|
+
it "should generate a yaml formatted file in ~/.mite.yml with the account and the apikey" do
|
70
|
+
File.stub!(:expand_path).and_return '/tmp/.mite.yml'
|
71
|
+
File.should_receive(:open).with('/tmp/.mite.yml', 'w').and_yield :file_handle
|
72
|
+
YAML.should_receive(:dump).with({:account => 'demo', :apikey => '123'}, :file_handle)
|
73
|
+
@application.run
|
74
|
+
end
|
75
|
+
|
76
|
+
it "should tell something nice if the bash completion setup fails" do
|
77
|
+
@application.stub!(:try_to_setup_bash_completion).and_return false
|
78
|
+
@application.should_receive(:tell).with "Could't set up bash completion. I'm terribly frustrated. Maybe 'mite help' helps out."
|
79
|
+
|
80
|
+
File.stub!(:open) # prevents the yml file to be written
|
81
|
+
@application.run
|
82
|
+
end
|
83
|
+
|
84
|
+
describe 'and setup bash completion' do
|
85
|
+
it "should append the bash completion call for mite to ~/.bash_completion if it exists and return true" do
|
86
|
+
File.stub!(:expand_path).and_return '/tmp/.bash_completion'
|
87
|
+
File.should_receive(:exist?).with('/tmp/.bash_completion').and_return true
|
88
|
+
file_handle = stub('file_handle')
|
89
|
+
File.should_receive(:open).with('/tmp/.bash_completion', 'a').and_yield file_handle
|
90
|
+
file_handle.should_receive(:puts).with("\n\ncomplete -C \"mite auto-complete\" mite")
|
91
|
+
|
92
|
+
File.stub!(:read).and_return ''
|
93
|
+
@application.send(:try_to_setup_bash_completion).should == true
|
94
|
+
end
|
95
|
+
|
96
|
+
it "should try '~/.bash_completion', '~/.bash_profile', '~/.bash_login', '~/.bashrc'" do
|
97
|
+
files = ['~/.bash_completion', '~/.bash_profile', '~/.bash_login', '~/.bashrc']
|
98
|
+
files_regexp = files.map {|f| Regexp.escape(f)}.join('|')
|
99
|
+
File.should_receive(:expand_path).with(
|
100
|
+
Regexp.new(files_regexp)
|
101
|
+
).exactly(files.size).times
|
102
|
+
|
103
|
+
File.stub!(:exist?).and_return false
|
104
|
+
@application.send :try_to_setup_bash_completion
|
105
|
+
end
|
106
|
+
|
107
|
+
it "should not open a file handle if the file does not exist" do
|
108
|
+
File.stub!(:exist?).and_return false
|
109
|
+
File.should_not_receive(:open)
|
110
|
+
@application.send :try_to_setup_bash_completion
|
111
|
+
end
|
112
|
+
|
113
|
+
it "should not append the bash completion call twice" do
|
114
|
+
File.stub!(:read).and_return "\n\ncomplete -C \"mite auto-complete\" mite"
|
115
|
+
File.should_not_receive(:open)
|
116
|
+
@application.send :try_to_setup_bash_completion
|
117
|
+
end
|
118
|
+
|
119
|
+
it "should return false if the bash completion could not be set up" do
|
120
|
+
File.stub!(:exist?).and_return false
|
121
|
+
@application.send(:try_to_setup_bash_completion).should == false
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
it "should raise an error if one of the last two arguments is missing" do
|
126
|
+
application = MightyMite::Application.new ['configure', 'faildemo']
|
127
|
+
lambda {
|
128
|
+
application.run
|
129
|
+
}.should raise_error(MightyMite::Exception)
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
describe 'the auto-complete argument' do
|
134
|
+
before(:each) do
|
135
|
+
@application = MightyMite::Application.new ['auto-complete']
|
136
|
+
@application.stub!(:tell)
|
137
|
+
|
138
|
+
@autocomplete = stub('autocomplete', :completion_table => {}, :completion_table= => nil, :suggestions => [])
|
139
|
+
MightyMite::Autocomplete.stub!(:new).and_return @autocomplete
|
140
|
+
end
|
141
|
+
|
142
|
+
it "should create a new instance of MightyMite::Autocomplete setting the calling_script" do
|
143
|
+
MightyMite.stub!(:calling_script).and_return '/usr/local/bin/mite'
|
144
|
+
MightyMite::Autocomplete.should_receive(:new).with '/usr/local/bin/mite'
|
145
|
+
@application.run
|
146
|
+
end
|
147
|
+
|
148
|
+
it "should unmarshal the cached completion table from ~/.mite.cache if it exists" do
|
149
|
+
File.stub!(:exist?).and_return true
|
150
|
+
File.should_receive(:read).and_return :marshal_data
|
151
|
+
Marshal.should_receive(:load).and_return :cached_completion_table
|
152
|
+
@autocomplete.should_receive(:completion_table=).with :cached_completion_table
|
153
|
+
@autocomplete.stub!(:suggestions).and_return []
|
154
|
+
@application.run
|
155
|
+
end
|
156
|
+
|
157
|
+
it "should tell each suggestion from MightyMite::Autocomplete" do
|
158
|
+
File.stub!(:exist?).and_return true
|
159
|
+
File.stub!(:read)
|
160
|
+
Marshal.stub!(:load)
|
161
|
+
@autocomplete.stub!(:suggestions).and_return ['Heinz', 'Peter']
|
162
|
+
@application.should_receive(:tell).with(/Heinz|Peter/).exactly(2).times
|
163
|
+
@application.run
|
164
|
+
end
|
165
|
+
|
166
|
+
it "should wrap suggestions inside quotes if they are spaced" do
|
167
|
+
File.stub!(:exist?).and_return true
|
168
|
+
File.stub!(:read)
|
169
|
+
Marshal.stub!(:load)
|
170
|
+
@autocomplete.stub!(:suggestions).and_return ['I need quotes', 'MeNot']
|
171
|
+
@application.should_receive(:tell).with(/"I need quotes"|MeNot/).exactly(2).times
|
172
|
+
@application.run
|
173
|
+
end
|
174
|
+
|
175
|
+
shared_examples_for 'an uncached completion table' do
|
176
|
+
before(:each) do
|
177
|
+
File.stub!(:exist?).and_return false
|
178
|
+
|
179
|
+
Mite::Project.stub!(:all).and_return [stub('project', :name => 'Demo Project')]
|
180
|
+
Mite::Service.stub!(:all).and_return [stub('service', :name => 'late night programming')]
|
181
|
+
Mite::TimeEntry.stub!(:all).and_return [stub('time entry', :note => 'shit 02:13 is really late')]
|
182
|
+
|
183
|
+
File.stub!(:open)
|
184
|
+
Marshal.stub!(:dump)
|
185
|
+
|
186
|
+
@completion_table = {
|
187
|
+
0 => ['Demo Project'],
|
188
|
+
1 => ['late night programming'],
|
189
|
+
2 => ['"0:05"', '"0:05+"', '"0:15"', '"0:15+"', '"0:30"', '"0:30+"', '"1:00"', '"1:00+"'],
|
190
|
+
3 => ['shit 02:13 is really late']
|
191
|
+
}
|
192
|
+
end
|
193
|
+
|
194
|
+
it "should create a new completion table" do
|
195
|
+
@application.send(:rebuild_completion_table).should == @completion_table
|
196
|
+
end
|
197
|
+
|
198
|
+
it "should save the new completion table to ~/.mite.cache" do
|
199
|
+
File.stub!(:expand_path).and_return '/tmp/.mite.cache'
|
200
|
+
File.should_receive(:open).with('/tmp/.mite.cache', 'w').and_yield :file_handle
|
201
|
+
Marshal.should_receive(:dump).with(@completion_table, :file_handle)
|
202
|
+
@application.run
|
203
|
+
end
|
204
|
+
end
|
205
|
+
|
206
|
+
describe 'and the completion table is not cached' do
|
207
|
+
it_should_behave_like 'an uncached completion table'
|
208
|
+
end
|
209
|
+
|
210
|
+
end
|
211
|
+
|
212
|
+
describe 'the rebuild-cache argument' do
|
213
|
+
before(:each) do
|
214
|
+
@application = MightyMite::Application.new ['rebuild-cache']
|
215
|
+
@application.stub!(:tell)
|
216
|
+
end
|
217
|
+
|
218
|
+
it "should delete the file at ~/.mite.cache if it exists" do
|
219
|
+
File.stub!(:exist?).and_return true
|
220
|
+
File.stub!(:expand_path).and_return '/tmp/.mite.cache'
|
221
|
+
File.should_receive(:delete).with '/tmp/.mite.cache'
|
222
|
+
@application.run
|
223
|
+
end
|
224
|
+
|
225
|
+
it "should not call delete on File if ~/.mite.cache does not exist" do
|
226
|
+
File.stub!(:exist?).and_return false
|
227
|
+
File.should_not_receive(:delete)
|
228
|
+
@application.run
|
229
|
+
end
|
230
|
+
|
231
|
+
it "should tell something nice if the cache has been rebuild" do
|
232
|
+
@application.should_receive(:tell).with 'The rebuilding of the cache has been done, Master. Your wish is my command.'
|
233
|
+
@application.run
|
234
|
+
end
|
235
|
+
|
236
|
+
it_should_behave_like 'an uncached completion table'
|
237
|
+
end
|
238
|
+
|
239
|
+
describe 'the simple report argument' do
|
240
|
+
shared_examples_for 'a simple report' do
|
241
|
+
before(:each) do
|
242
|
+
@application = MightyMite::Application.new [@argument]
|
243
|
+
@application.stub!(:tell)
|
244
|
+
|
245
|
+
@time_entry = stub('time_entry', :inspect => 'I am a time entry.', :revenue => 1200)
|
246
|
+
@time_entry_with_nil_revenue = stub('time_entry_without_revenue', :inspect => 'I am a time entry.', :revenue => nil)
|
247
|
+
@time_entry_with_nil_revenue.stub!(:revenue).and_return nil
|
248
|
+
Mite::TimeEntry.stub!(:all).and_return [@time_entry, @time_entry, @time_entry_with_nil_revenue]
|
249
|
+
end
|
250
|
+
|
251
|
+
it "should tell an inspection of each time entry" do
|
252
|
+
Mite::TimeEntry.should_receive(:all).with(:params => hash_including(:at => @argument))
|
253
|
+
@time_entry.should_receive(:inspect).exactly(2).times
|
254
|
+
@time_entry_with_nil_revenue.should_receive(:inspect).at_least(:once)
|
255
|
+
@application.should_receive(:tell).with('I am a time entry.').exactly(3).times
|
256
|
+
@application.run
|
257
|
+
end
|
258
|
+
|
259
|
+
it "should only output the time entries of the current user" do
|
260
|
+
Mite::TimeEntry.should_receive(:all).with(:params => hash_including(:user_id => 'current'))
|
261
|
+
@application.run
|
262
|
+
end
|
263
|
+
|
264
|
+
it "should tell #{@argument}'s revenue, nicely formatted and colorized in lightgreen" do
|
265
|
+
@application.should_receive(:tell).with("\e[1;32;49m2400.00 $\e[0m").at_least(:once)
|
266
|
+
@application.run
|
267
|
+
end
|
268
|
+
end
|
269
|
+
|
270
|
+
['today', 'yesterday', 'this_week', 'last_week', 'this_month', 'last_month'].each do |argument|
|
271
|
+
describe argument do
|
272
|
+
before(:each) { @argument = argument }
|
273
|
+
it_should_behave_like 'a simple report'
|
274
|
+
end
|
275
|
+
end
|
276
|
+
end
|
277
|
+
|
278
|
+
describe 'the stop argument' do
|
279
|
+
before(:each) do
|
280
|
+
@application = MightyMite::Application.new ['stop']
|
281
|
+
@application.stub!(:tell)
|
282
|
+
|
283
|
+
time_entry = stub('time_entry', :inspect => 'hey there.')
|
284
|
+
@current_tracker = stub('tracker', :time_entry => time_entry)
|
285
|
+
@current_tracker.stub!(:stop).and_return @current_tracker
|
286
|
+
Mite::Tracker.stub!(:current).and_return @current_tracker
|
287
|
+
end
|
288
|
+
|
289
|
+
it "should call stop on the current tracker" do
|
290
|
+
@current_tracker.should_receive :stop
|
291
|
+
@application.run
|
292
|
+
end
|
293
|
+
|
294
|
+
it "should do nothing if there is no current tracker" do
|
295
|
+
Mite::Tracker.stub!(:current).and_return nil
|
296
|
+
@application.run
|
297
|
+
end
|
298
|
+
|
299
|
+
it "should tell the inspection of the tracker's time entry if it has been stopped" do
|
300
|
+
@application.should_receive(:tell).with 'hey there.'
|
301
|
+
@application.run
|
302
|
+
end
|
303
|
+
end
|
304
|
+
|
305
|
+
describe 'the start argument' do
|
306
|
+
before(:each) do
|
307
|
+
@application = MightyMite::Application.new ['start']
|
308
|
+
@application.stub!(:tell)
|
309
|
+
|
310
|
+
@time_entry = stub('time_entry', :start_tracker => nil, :inspect => 'I was started.')
|
311
|
+
Mite::TimeEntry.stub!(:first).and_return @time_entry
|
312
|
+
end
|
313
|
+
|
314
|
+
it "should call start_tracker on the last time entry of today" do
|
315
|
+
# last time entry by time = first by list order
|
316
|
+
Mite::TimeEntry.should_receive(:first).with(:params => {:at => 'today'})
|
317
|
+
@time_entry.should_receive(:start_tracker)
|
318
|
+
@application.run
|
319
|
+
end
|
320
|
+
|
321
|
+
it "should tell an inspection of the last time entry if it has been started" do
|
322
|
+
@application.should_receive(:tell).with 'I was started.'
|
323
|
+
@application.run
|
324
|
+
end
|
325
|
+
|
326
|
+
it "should tell something nice if there is no time entry to start" do
|
327
|
+
Mite::TimeEntry.stub!(:first).and_return nil
|
328
|
+
@application.should_receive(:tell).with "Oh my dear! I tried hard, but I could'nt find any time entry for today."
|
329
|
+
@application.run
|
330
|
+
end
|
331
|
+
end
|
332
|
+
|
333
|
+
end
|
334
|
+
|
335
|
+
describe MightyMite::Application, 'dynamic time entry creation' do
|
336
|
+
before(:each) do
|
337
|
+
MightyMite.stub!(:load_configuration)
|
338
|
+
|
339
|
+
@time_entry = stub('time_entry', :start_tracker => nil, :inspect => '')
|
340
|
+
Mite::TimeEntry.stub!(:create).and_return @time_entry
|
341
|
+
Mite::Project.stub! :first
|
342
|
+
Mite::Project.stub! :create
|
343
|
+
Mite::Service.stub! :first
|
344
|
+
Mite::Service.stub! :create
|
345
|
+
end
|
346
|
+
|
347
|
+
def new_application(args=[])
|
348
|
+
application = MightyMite::Application.new args
|
349
|
+
application.stub!(:tell)
|
350
|
+
application
|
351
|
+
end
|
352
|
+
|
353
|
+
it "should tell an inspection of the time entry" do
|
354
|
+
@time_entry.stub!(:inspect).and_return 'My name is entry, time entry.'
|
355
|
+
application = new_application(['Project', 'Service', 'Note'])
|
356
|
+
application.should_receive(:tell).with 'My name is entry, time entry.'
|
357
|
+
application.run
|
358
|
+
end
|
359
|
+
|
360
|
+
describe 'the + argument' do
|
361
|
+
it "should create and start a new time entry" do
|
362
|
+
time_entry = stub('time_entry')
|
363
|
+
Mite::TimeEntry.should_receive(:create).and_return time_entry
|
364
|
+
time_entry.should_receive :start_tracker
|
365
|
+
new_application(['+']).run
|
366
|
+
end
|
367
|
+
end
|
368
|
+
|
369
|
+
describe 'with a time given' do
|
370
|
+
it "should parse minutes as integer out of h:mm(+)?" do
|
371
|
+
new_application.send(:parse_minutes, '1:18').should == 78
|
372
|
+
new_application.send(:parse_minutes, '72:00').should == 4320
|
373
|
+
new_application.send(:parse_minutes, '0:01+').should == 1
|
374
|
+
end
|
375
|
+
|
376
|
+
it "should parse minutes as integer out of h(:)?(+)?" do
|
377
|
+
new_application.send(:parse_minutes, '3').should == 180
|
378
|
+
new_application.send(:parse_minutes, '2:').should == 120
|
379
|
+
new_application.send(:parse_minutes, '1.5').should == 90
|
380
|
+
new_application.send(:parse_minutes, '2.5+').should == 150
|
381
|
+
new_application.send(:parse_minutes, '5:').should == 300
|
382
|
+
new_application.send(:parse_minutes, '1:+').should == 60
|
383
|
+
new_application.send(:parse_minutes, '0.5:').should == 30
|
384
|
+
end
|
385
|
+
|
386
|
+
it "should parse minutes as nil out of +" do
|
387
|
+
new_application.send(:parse_minutes, '+').should == nil
|
388
|
+
end
|
389
|
+
|
390
|
+
it "should add the parsed minutes to the attributes" do
|
391
|
+
Mite::TimeEntry.should_receive(:create).with hash_including(:minutes => 78)
|
392
|
+
new_application(['ARG1', 'ARG2', '1:18', 'ARG4']).run
|
393
|
+
end
|
394
|
+
|
395
|
+
it "should start the tracker for the time entry if the attributes is suffixed with '+'" do
|
396
|
+
@time_entry.should_receive(:start_tracker)
|
397
|
+
new_application(['ARG1', 'ARG2', '1:18+', 'ARG4']).run
|
398
|
+
end
|
399
|
+
end
|
400
|
+
|
401
|
+
describe 'with a project name given' do
|
402
|
+
before(:each) do
|
403
|
+
@project = stub('project', :id => 1)
|
404
|
+
Mite::Project.stub!(:first).and_return @project
|
405
|
+
end
|
406
|
+
|
407
|
+
it "should try if the first argument is an existing project" do
|
408
|
+
Mite::Project.should_receive(:first).with(:params => {:name => 'Project No1'})
|
409
|
+
new_application(['Project No1']).run
|
410
|
+
end
|
411
|
+
|
412
|
+
it "should add the project id to the attributes if a project was found" do
|
413
|
+
Mite::TimeEntry.should_receive(:create).with hash_including(:project_id => 1)
|
414
|
+
new_application(['Project No1']).run
|
415
|
+
end
|
416
|
+
|
417
|
+
it "should create a new project unless a project was found" do
|
418
|
+
Mite::Project.stub!(:first).and_return nil
|
419
|
+
@project.stub!(:id).and_return 1234
|
420
|
+
Mite::Project.stub!(:create).and_return @project
|
421
|
+
Mite::TimeEntry.should_receive(:create).with hash_including(:project_id => 1234)
|
422
|
+
new_application(['I do not exist']).run
|
423
|
+
end
|
424
|
+
|
425
|
+
it "should not create a new project if the first argument is a time argument" do
|
426
|
+
Mite::Project.stub!(:first).and_return nil
|
427
|
+
Mite::Project.should_not_receive(:create)
|
428
|
+
new_application(['1:11+']).run
|
429
|
+
end
|
430
|
+
end
|
431
|
+
|
432
|
+
describe "with a service name given" do
|
433
|
+
before(:each) do
|
434
|
+
@service = stub('service', :id => 2)
|
435
|
+
Mite::Service.stub!(:first).and_return @service
|
436
|
+
end
|
437
|
+
|
438
|
+
it "should try if the second argument is an existing service" do
|
439
|
+
Mite::Service.should_receive(:first).with(:params => {:name => 'Carwashing'})
|
440
|
+
new_application(['1', 'Carwashing']).run
|
441
|
+
end
|
442
|
+
|
443
|
+
it "should add the service id to the attributes if a service was found" do
|
444
|
+
Mite::TimeEntry.should_receive(:create).with hash_including(:service_id => 2)
|
445
|
+
new_application(['1', 'Read a book']).run
|
446
|
+
end
|
447
|
+
|
448
|
+
it "should not add the service id to the attributes unless a service was found" do
|
449
|
+
Mite::Service.stub!(:first).and_return nil
|
450
|
+
Mite::TimeEntry.should_not_receive(:create).with hash_including(:service_id => 2)
|
451
|
+
new_application(['1', 'Write a book']).run
|
452
|
+
end
|
453
|
+
|
454
|
+
it "should create a new service unless a service was found" do
|
455
|
+
Mite::Service.stub!(:first).and_return nil
|
456
|
+
@service.stub!(:id).and_return 15
|
457
|
+
Mite::Service.stub!(:create).and_return @service
|
458
|
+
Mite::TimeEntry.should_receive(:create).with hash_including(:service_id => 15)
|
459
|
+
new_application(['1', 'I do not exist yet']).run
|
460
|
+
end
|
461
|
+
|
462
|
+
it "should not create a new service if the second argument is a time argument" do
|
463
|
+
Mite::Service.stub!(:first).and_return nil
|
464
|
+
Mite::Service.should_not_receive(:create)
|
465
|
+
new_application(['1', '0:18']).run
|
466
|
+
end
|
467
|
+
|
468
|
+
it "should do nothing on services if there is no second argument" do
|
469
|
+
application = new_application(['1'])
|
470
|
+
application.should_not_receive :find_or_create_service
|
471
|
+
application.run
|
472
|
+
end
|
473
|
+
end
|
474
|
+
|
475
|
+
describe "with a note given" do
|
476
|
+
it "should parse the note out of the arguments" do
|
477
|
+
new_application.send(:parse_note, ['0:12', 'gnarr gnarr'], '0:12').should == 'gnarr gnarr'
|
478
|
+
new_application.send(:parse_note, ['1', '1:30+', 'bla bla'], '1:30+').should == 'bla bla'
|
479
|
+
new_application.send(:parse_note, ['Project', 'Service', 'NOTE!'], nil).should == 'NOTE!'
|
480
|
+
end
|
481
|
+
|
482
|
+
it "should add the note to the attributes if the fourth argument is given" do
|
483
|
+
Mite::TimeEntry.should_receive(:create).with hash_including(:note => 'Reminder')
|
484
|
+
new_application(['ARG1', 'ARG2', '3+', 'Reminder']).run
|
485
|
+
end
|
486
|
+
|
487
|
+
it "should add the note to the attributes if it is third argument and no time is given" do
|
488
|
+
Mite::TimeEntry.should_receive(:create).with hash_including(:note => 'bla bla')
|
489
|
+
new_application(['ARG1', 'ARG2', 'bla bla']).run
|
490
|
+
end
|
491
|
+
|
492
|
+
it "should add the note to the attributes if a time argument is followed by a note" do
|
493
|
+
Mite::TimeEntry.should_receive(:create).with hash_including(:note => 'gnarr gnarr')
|
494
|
+
new_application(['1:02', 'gnarr gnarr']).run
|
495
|
+
Mite::TimeEntry.should_receive(:create).with hash_including(:note => 'glubb glubb')
|
496
|
+
new_application(['ARG1', '3:04', 'glubb glubb']).run
|
497
|
+
end
|
498
|
+
end
|
499
|
+
end
|
500
|
+
|
501
|
+
describe MightyMite::Application, 'flirt' do
|
502
|
+
before(:each) do
|
503
|
+
MightyMite.stub!(:load_configuration)
|
504
|
+
end
|
505
|
+
|
506
|
+
it "should return a random flirt as string" do
|
507
|
+
MightyMite::Application.new.flirt.should be_kind_of(String)
|
508
|
+
end
|
509
|
+
end
|
@@ -0,0 +1,100 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
|
2
|
+
|
3
|
+
describe MightyMite::Autocomplete, 'new' do
|
4
|
+
it "should set calling_script" do
|
5
|
+
autocomplete = MightyMite::Autocomplete.new('/usr/local/bin/mite')
|
6
|
+
autocomplete.instance_variable_get('@calling_script').should == '/usr/local/bin/mite'
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
describe MightyMite::Autocomplete do
|
11
|
+
before(:each) do
|
12
|
+
@autocomplete = MightyMite::Autocomplete.new '/usr/local/bin/test_command'
|
13
|
+
@autocomplete.completion_table = {
|
14
|
+
0 => ['argument1', 'argument1a', 'argument1b', 'argument1c'],
|
15
|
+
1 => ['Homer', 'Simpsons', 'Holy', 'Holy Moly', 'Holy Grail'],
|
16
|
+
2 => ['I love spaces']
|
17
|
+
}
|
18
|
+
ENV['COMP_LINE'] = "./test_command argument1 Holy \"I love spaces\""
|
19
|
+
ENV['COMP_POINT'] = '27'
|
20
|
+
end
|
21
|
+
|
22
|
+
describe 'argument_string' do
|
23
|
+
it "should return a string of all arguments without the calling script" do
|
24
|
+
@autocomplete.argument_string.should == 'argument1 Holy "I love spaces"'
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe 'partial_argument_string' do
|
29
|
+
it "should return the arguments part of the bash line" do
|
30
|
+
@autocomplete.partial_argument_string.should == 'argument1 Holy'
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should be able to handle unmatched quotes" do
|
34
|
+
ENV['COMP_LINE'] = "./test_command \"arg "
|
35
|
+
ENV['COMP_POINT'] = '20'
|
36
|
+
@autocomplete.partial_argument_string.should == '"arg "'
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe 'args' do
|
41
|
+
it "should return an array of arguments" do
|
42
|
+
@autocomplete.args.should == ['argument1', 'Holy', 'I love spaces']
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
describe 'cursor_position' do
|
47
|
+
it "should return the cursor position as integer" do
|
48
|
+
@autocomplete.cursor_position.should == 27
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
describe 'current_word' do
|
53
|
+
it "should return the current word at the cursor position" do
|
54
|
+
@autocomplete.current_word.should == 'Holy'
|
55
|
+
end
|
56
|
+
|
57
|
+
it "should be able to handle unmatched quotes" do
|
58
|
+
ENV['COMP_LINE'] = "./test_command \"arg "
|
59
|
+
ENV['COMP_POINT'] = '20'
|
60
|
+
@autocomplete.current_word.should == 'arg '
|
61
|
+
end
|
62
|
+
|
63
|
+
it "should return nil if the last word has been completed" do
|
64
|
+
ENV['COMP_LINE'] = "./test_command arg0 "
|
65
|
+
ENV['COMP_POINT'] = '20'
|
66
|
+
@autocomplete.current_word.should == nil
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
describe 'current_argument_index' do
|
71
|
+
it "should return the index of the argument at the cursor position" do
|
72
|
+
@autocomplete.current_argument_index.should == 1
|
73
|
+
end
|
74
|
+
|
75
|
+
it "should default to 0 if there are no args yet" do
|
76
|
+
ENV['COMP_LINE'] = "./test_command "
|
77
|
+
ENV['COMP_POINT'] = '15'
|
78
|
+
@autocomplete.current_argument_index.should == 0
|
79
|
+
end
|
80
|
+
|
81
|
+
it "should return the size of the existing arguments plus 1 if the cursor position is at the end" do
|
82
|
+
ENV['COMP_LINE'] = "./test_command arg_index0 arg_index1 "
|
83
|
+
ENV['COMP_POINT'] = '37'
|
84
|
+
@autocomplete.current_argument_index.should == 2
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
describe 'suggestions' do
|
89
|
+
it "should return the suggested values from the completion table at the current argument index" do
|
90
|
+
@autocomplete.suggestions.should == ['Holy', 'Holy Moly', 'Holy Grail']
|
91
|
+
end
|
92
|
+
|
93
|
+
it "should return an empty array if the current argument index is out of range" do
|
94
|
+
@autocomplete.stub!(:current_argument_index).and_return 50
|
95
|
+
@autocomplete.suggestions.should == []
|
96
|
+
end
|
97
|
+
|
98
|
+
end
|
99
|
+
|
100
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe MightyMite, 'load_configuration' do
|
4
|
+
def fake_configuration
|
5
|
+
File.stub!(:exist?).and_return true
|
6
|
+
File.stub!(:read).and_return :yaml_data
|
7
|
+
YAML.stub!(:load).and_return({:account => 'demo', :apikey => '123'})
|
8
|
+
end
|
9
|
+
|
10
|
+
describe 'configuration file exists' do
|
11
|
+
before(:each) do
|
12
|
+
fake_configuration
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should set the account name for Mite" do
|
16
|
+
Mite.should_receive(:account=).with 'demo'
|
17
|
+
MightyMite.load_configuration
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should set the apikey for Mite" do
|
21
|
+
Mite.should_receive(:key=).with '123'
|
22
|
+
MightyMite.load_configuration
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe 'configuration file does not exist' do
|
27
|
+
before(:each) do
|
28
|
+
File.stub!(:exist?).and_return false
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should raise an error if the configuration file is missing" do
|
32
|
+
lambda {
|
33
|
+
MightyMite.load_configuration
|
34
|
+
}.should raise_error
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
describe MightyMite, 'run' do
|
40
|
+
it "should create a new instance of the Application class using the given arguments" do
|
41
|
+
MightyMite::Application.should_receive(:new).with(['arg1', 'arg2']).and_return stub('application', :run => nil)
|
42
|
+
MightyMite.run(['arg1', 'arg2'])
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should call run on the new instance" do
|
46
|
+
application = stub('application')
|
47
|
+
MightyMite::Application.stub!(:new).and_return application
|
48
|
+
application.should_receive :run
|
49
|
+
MightyMite.run([])
|
50
|
+
end
|
51
|
+
end
|