one_inch_punch 0.2.2 → 0.2.3

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/History.txt CHANGED
@@ -1,3 +1,10 @@
1
+ == 0.2.3 2008-12-11
2
+
3
+ * 1 enhancements:
4
+ * Logging a message now automatically adds a time
5
+ * A time can be specified for the log message (with now as a default)
6
+ * punch command takes options for message logging
7
+
1
8
  == 0.2.2 2008-12-01
2
9
 
3
10
  * 1 enhancement:
data/Manifest.txt CHANGED
@@ -19,9 +19,7 @@ spec/fixnum_spec.rb
19
19
  spec/punch_command_spec.rb
20
20
  spec/punch_instance_spec.rb
21
21
  spec/punch_spec.rb
22
- spec/spec.opts
23
22
  spec/spec_helper.rb
24
23
  tasks/deployment.rake
25
24
  tasks/environment.rake
26
- tasks/rspec.rake
27
25
  tasks/website.rake
data/bin/punch CHANGED
@@ -101,7 +101,7 @@ commands = {
101
101
  'log' => lambda do |project|
102
102
  if project
103
103
  if message = ARGV[2]
104
- if Punch.log(project, message)
104
+ if Punch.log(project, message, OPTIONS)
105
105
  Punch.write
106
106
  else
107
107
  puts "Not punched in to '#{project}'"
data/config/hoe.rb CHANGED
@@ -11,8 +11,8 @@ EXTRA_DEPENDENCIES = [
11
11
  # ['activesupport', '>= 1.3.1']
12
12
  ] # An array of rubygem dependencies [name, version]
13
13
  EXTRA_DEV_DEPENDENCIES = [
14
- ['rspec', '>= 1.1.4'],
15
- ['mocha', '>= 0.9.1']
14
+ ['bacon', '>= 1.1.0'],
15
+ ['facon', '>= 0.4.1']
16
16
  ] # An array of rubygem dependencies [name, version]
17
17
 
18
18
  @config_file = "~/.rubyforge/user-config.yml"
@@ -33,7 +33,7 @@ class Punch
33
33
  self.class.total(project, options)
34
34
  end
35
35
 
36
- def log(message)
37
- self.class.log(project, message)
36
+ def log(message, options = {})
37
+ self.class.log(project, message, options)
38
38
  end
39
39
  end
data/lib/punch/version.rb CHANGED
@@ -2,7 +2,7 @@ class Punch
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
4
  MINOR = 2
5
- TINY = 2
5
+ TINY = 3
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
data/lib/punch.rb CHANGED
@@ -62,8 +62,8 @@ class Punch
62
62
  data[project] ||= []
63
63
  time = time_from_options(options)
64
64
  data[project].push({'in' => time})
65
- log(project, "punch in @ #{time.strftime('%Y-%m-%dT%H:%M:%S%z')}")
66
- log(project, options[:message]) if options[:message]
65
+ log(project, 'punch in', :time => time)
66
+ log(project, options[:message], :time => time) if options[:message]
67
67
  true
68
68
  end
69
69
 
@@ -104,11 +104,13 @@ class Punch
104
104
  end
105
105
  end
106
106
 
107
- def log(project, message)
107
+ def log(project, message, options = {})
108
+ raise ArgumentError, "Message is not an optional argument" if message.is_a?(Hash)
108
109
  return false unless in?(project)
109
110
  project_data = data[project].last
110
111
  project_data['log'] ||= []
111
- project_data['log'].push message
112
+ time = time_from_options(options)
113
+ project_data['log'].push "#{message} @ #{time.strftime('%Y-%m-%dT%H:%M:%S%z')}"
112
114
  true
113
115
  end
114
116
 
@@ -118,8 +120,8 @@ class Punch
118
120
  def do_out_single(project, options)
119
121
  return false if out?(project)
120
122
  time = time_from_options(options)
121
- log(project, options[:message]) if options[:message]
122
- log(project, "punch out @ #{time.strftime('%Y-%m-%dT%H:%M:%S%z')}")
123
+ log(project, options[:message], :time => time) if options[:message]
124
+ log(project, 'punch out', :time => time)
123
125
  data[project].last['out'] = time
124
126
  end
125
127
 
data/spec/fixnum_spec.rb CHANGED
@@ -2,7 +2,7 @@ require File.dirname(__FILE__) + '/spec_helper.rb'
2
2
 
3
3
  describe Fixnum do
4
4
  it 'should give an elapsed time' do
5
- 50.should respond_to(:elapsed_time)
5
+ 50.should.respond_to(:elapsed_time)
6
6
  end
7
7
 
8
8
  describe 'giving an elapsed time' do
@@ -1,77 +1,78 @@
1
1
  require File.dirname(__FILE__) + '/spec_helper.rb'
2
2
 
3
- describe 'punch command' do
4
- def run_command(*args)
5
- Object.const_set(:ARGV, args)
6
- begin
7
- eval File.read(File.join(File.dirname(__FILE__), *%w[.. bin punch]))
8
- rescue SystemExit
9
- end
3
+ def run_command(*args)
4
+ Object.const_set(:ARGV, args)
5
+ begin
6
+ eval File.read(File.join(File.dirname(__FILE__), *%w[.. bin punch]))
7
+ rescue SystemExit
10
8
  end
11
-
12
- before :each do
9
+ end
10
+
11
+
12
+ describe 'punch command' do
13
+ before do
13
14
  [:ARGV, :OPTIONS, :MANDATORY_OPTIONS].each do |const|
14
15
  Object.send(:remove_const, const) if Object.const_defined?(const)
15
16
  end
16
17
 
17
- @states = {}
18
- %w[puts load write].each do |state|
19
- @states[state] = states(state).starts_as('setup')
20
- end
21
-
22
- self.stubs(:puts).when(@states['puts'].is('setup'))
23
- Punch.stubs(:load).when(@states['load'].is('setup'))
24
- Punch.stubs(:write).when(@states['write'].is('setup'))
18
+ self.stub!(:puts)
19
+ Punch.stub!(:load)
20
+ Punch.stub!(:write)
25
21
 
26
22
  @project = 'myproj'
27
23
  end
28
24
 
29
25
  it 'should exist' do
30
- lambda { run_command }.should_not raise_error(Errno::ENOENT)
26
+ lambda { run_command }.should.not.raise(Errno::ENOENT)
31
27
  end
32
28
 
33
29
  it 'should require a command' do
34
- self.expects(:puts).with(regexp_matches(/usage.+command/i))
30
+ self.should.receive(:puts) do |output|
31
+ output.should.match(/usage.+command/i)
32
+ end
35
33
  run_command
36
34
  end
37
35
 
38
36
  describe "when the command is 'total'" do
39
- before :each do
40
- Punch.stubs(:total)
37
+ before do
38
+ Punch.stub!(:total)
41
39
  end
42
40
 
43
41
  it 'should load punch data' do
44
- Punch.expects(:load)
42
+ Punch.should.receive(:load)
45
43
  run_command('total', @project)
46
44
  end
47
45
 
48
46
  it 'should get the total for the requested project' do
49
- Punch.expects(:total).with(@project, anything)
47
+ Punch.should.receive(:total) do |proj, _|
48
+ proj.should == @project
49
+ end
50
50
  run_command('total', @project)
51
51
  end
52
52
 
53
53
  it 'should get the total for all projects if none given' do
54
- Punch.expects(:total).with(nil, anything)
54
+ Punch.should.receive(:total) do |proj, _|
55
+ proj.should.be.nil
56
+ end
55
57
  run_command('total')
56
58
  end
57
59
 
58
60
  it 'should output the total' do
59
61
  result = 'total data'
60
- Punch.stubs(:total).returns(result)
61
- self.expects(:puts).with(result.inspect)
62
+ Punch.stub!(:total).and_return(result)
63
+ self.should.receive(:puts).with(result.inspect)
62
64
  run_command('total', @project)
63
65
  end
64
66
 
65
67
  it 'should output the total as YAML if no project given' do
66
68
  result = 'total data'
67
- Punch.stubs(:total).returns(result)
68
- self.expects(:puts).with(result.to_yaml)
69
+ Punch.stub!(:total).and_return(result)
70
+ self.should.receive(:puts).with(result.to_yaml)
69
71
  run_command('total')
70
72
  end
71
73
 
72
74
  it 'should not write the data' do
73
- @states['write'].become('test')
74
- Punch.expects(:write).never.when(@states['write'].is('test'))
75
+ Punch.should.receive(:write).never
75
76
  run_command('total')
76
77
  end
77
78
 
@@ -79,300 +80,353 @@ describe 'punch command' do
79
80
  it "should pass on an 'after' time option given by --after" do
80
81
  time_option = '2008-08-26 09:47'
81
82
  time = Time.local(2008, 8, 26, 9, 47)
82
- Punch.expects(:total).with(@project, has_entry(:after => time))
83
+ Punch.should.receive(:total) do |proj, options|
84
+ proj.should == @project
85
+ options[:after].should == time
86
+ end
83
87
  run_command('total', @project, '--after', time_option)
84
88
  end
85
89
 
86
90
  it "should pass on a 'before' time option given by --before" do
87
91
  time_option = '2008-08-23 15:39'
88
92
  time = Time.local(2008, 8, 23, 15, 39)
89
- Punch.expects(:total).with(@project, has_entry(:before => time))
93
+ Punch.should.receive(:total) do |proj, options|
94
+ proj.should == @project
95
+ options[:before].should == time
96
+ end
90
97
  run_command('total', @project, '--before', time_option)
91
98
  end
92
99
 
93
100
  it 'should handle a time option given as a date' do
94
101
  time_option = '2008-08-23'
95
102
  time = Time.local(2008, 8, 23)
96
- Punch.expects(:total).with(@project, has_entry(:before => time))
103
+ Punch.should.receive(:total) do |proj, options|
104
+ proj.should == @project
105
+ options[:before].should == time
106
+ end
97
107
  run_command('total', @project, '--before', time_option)
98
108
  end
99
109
 
100
110
  it 'should accept time options if no project given' do
101
111
  time_option = '2008-08-26 09:47'
102
112
  time = Time.local(2008, 8, 26, 9, 47)
103
- Punch.expects(:total).with(nil, has_entry(:before => time))
113
+ Punch.should.receive(:total) do |proj, options|
114
+ proj.should.be.nil
115
+ options[:before].should == time
116
+ end
104
117
  run_command('total', '--before', time_option)
105
118
  end
106
119
 
107
120
  it 'should also pass the formatting option' do
108
121
  time_option = '2008-08-26 09:47'
109
- Punch.expects(:total).with(@project, has_entry(:format => true))
122
+ Punch.should.receive(:total) do |proj, options|
123
+ proj.should == @project
124
+ options[:format].should == true
125
+ end
110
126
  run_command('total', @project, '--before', time_option)
111
127
  end
112
128
  end
113
129
 
114
130
  it 'should pass only the formatting option if no options specified' do
115
- Punch.expects(:total).with(@project, {:format => true})
131
+ Punch.should.receive(:total) do |proj, options|
132
+ proj.should == @project
133
+ options[:format].should == true
134
+ end
116
135
  run_command('total', @project)
117
136
  end
118
137
  end
119
138
 
120
139
  describe "when the command is 'status'" do
121
- before :each do
122
- Punch.stubs(:status)
140
+ before do
141
+ Punch.stub!(:status)
123
142
  end
124
143
 
125
144
  it 'should load punch data' do
126
- Punch.expects(:load)
145
+ Punch.should.receive(:load)
127
146
  run_command('status', @project)
128
147
  end
129
148
 
130
149
  it 'should get the status for the requested project' do
131
- Punch.expects(:status).with(@project)
150
+ Punch.should.receive(:status).with(@project)
132
151
  run_command('status', @project)
133
152
  end
134
153
 
135
154
  it 'should get the status for all projects if none given' do
136
- Punch.expects(:status).with(nil)
155
+ Punch.should.receive(:status).with(nil)
137
156
  run_command('status')
138
157
  end
139
158
 
140
159
  it 'should output the status' do
141
160
  result = 'status data'
142
- Punch.stubs(:status).returns(result)
143
- self.expects(:puts).with(result.inspect)
161
+ Punch.stub!(:status).and_return(result)
162
+ self.should.receive(:puts).with(result.inspect)
144
163
  run_command('status', @project)
145
164
  end
146
165
 
147
166
  it 'should output the status as YAML if no project given' do
148
167
  result = 'status data'
149
- Punch.stubs(:status).returns(result)
150
- self.expects(:puts).with(result.to_yaml)
168
+ Punch.stub!(:status).and_return(result)
169
+ self.should.receive(:puts).with(result.to_yaml)
151
170
  run_command('status')
152
171
  end
153
172
 
154
173
  it 'should not write the data' do
155
- @states['write'].become('test')
156
- Punch.expects(:write).never.when(@states['write'].is('test'))
174
+ Punch.should.receive(:write).never
157
175
  run_command('status')
158
176
  end
159
177
  end
160
178
 
161
179
  describe "when the command is 'in'" do
162
- before :each do
163
- @states['in'] = states('in').starts_as('setup')
164
- Punch.stubs(:in).when(@states['write'].is('setup'))
180
+ before do
181
+ Punch.stub!(:in)
165
182
  end
166
183
 
167
184
  it 'should load punch data' do
168
- Punch.expects(:load)
185
+ Punch.should.receive(:load)
169
186
  run_command('in', @project)
170
187
  end
171
188
 
172
189
  it 'should punch in to the given project' do
173
- Punch.expects(:in).with(@project, {})
190
+ Punch.should.receive(:in).with(@project, {})
174
191
  run_command('in', @project)
175
192
  end
176
193
 
177
194
  it 'should pass a time if specified on the command line (with --time)' do
178
195
  time_option = '2008-08-23 15:39'
179
196
  time = Time.local(2008, 8, 23, 15, 39)
180
- Punch.expects(:in).with(@project, has_entry(:time => time))
197
+ Punch.should.receive(:in) do |proj, options|
198
+ proj.should == @project
199
+ options[:time].should == time
200
+ end
181
201
  run_command('in', @project, '--time', time_option)
182
202
  end
183
203
 
184
204
  it 'should pass a time if specified on the command line (with --at)' do
185
205
  time_option = '2008-08-23 15:39'
186
206
  time = Time.local(2008, 8, 23, 15, 39)
187
- Punch.expects(:in).with(@project, has_entry(:time => time))
207
+ Punch.should.receive(:in) do |proj, options|
208
+ proj.should == @project
209
+ options[:time].should == time
210
+ end
188
211
  run_command('in', @project, '--at', time_option)
189
212
  end
190
213
 
191
214
  it 'should pass a message if specified on the command line (with --message)' do
192
215
  message = 'About to do some amazing work'
193
- Punch.expects(:in).with(@project, has_entry(:message => message))
216
+ Punch.should.receive(:in) do |proj, options|
217
+ proj.should == @project
218
+ options[:message].should == message
219
+ end
194
220
  run_command('in', @project, '--message', message)
195
221
  end
196
222
 
197
223
  it 'should pass a message if specified on the command line (with -m)' do
198
224
  message = 'About to do some amazing work'
199
- Punch.expects(:in).with(@project, has_entry(:message => message))
225
+ Punch.should.receive(:in) do |proj, options|
226
+ proj.should == @project
227
+ options[:message].should == message
228
+ end
200
229
  run_command('in', @project, '-m', message)
201
230
  end
202
231
 
203
232
  describe 'when punched in successfully' do
204
- before :each do
205
- Punch.stubs(:in).returns(true)
233
+ before do
234
+ Punch.stub!(:in).and_return(true)
206
235
  end
207
236
 
208
237
  it 'should write the data' do
209
- Punch.expects(:write)
238
+ Punch.should.receive(:write)
210
239
  run_command('in', @project)
211
240
  end
212
241
 
213
242
  it 'should not print anything' do
214
- @states['puts'].become('test')
215
- self.expects(:puts).never.when(@states['puts'].is('test'))
243
+ self.should.receive(:puts).never
216
244
  run_command('in', @project)
217
245
  end
218
246
  end
219
247
 
220
248
  describe 'when not punched in successfully' do
221
- before :each do
222
- Punch.stubs(:in).returns(false)
249
+ before do
250
+ Punch.stub!(:in).and_return(false)
223
251
  end
224
252
 
225
253
  it 'should not write the data' do
226
- @states['write'].become('test')
227
- Punch.expects(:write).never.when(@states['write'].is('test'))
254
+ Punch.should.receive(:write).never
228
255
  run_command('in', @project)
229
256
  end
230
257
 
231
258
  it 'should print a message' do
232
- self.expects(:puts).with(regexp_matches(/already.+in/i))
259
+ self.should.receive(:puts) do |output|
260
+ output.should.match(/already.+in/i)
261
+ end
233
262
  run_command('in', @project)
234
263
  end
235
264
  end
236
265
 
237
266
  describe 'when no project given' do
238
267
  it 'should display an error message' do
239
- self.expects(:puts).with(regexp_matches(/project.+require/i))
268
+ self.should.receive(:puts) do |output|
269
+ output.should.match(/project.+require/i)
270
+ end
240
271
  run_command('in')
241
272
  end
242
273
 
243
274
  it 'should not punch in' do
244
- @states['in'].become('test')
245
- Punch.stubs(:write)
246
- Punch.expects(:in).never.when(@states['in'].is('test'))
275
+ Punch.stub!(:write)
276
+ Punch.should.receive(:in).never
247
277
  run_command('in')
248
278
  end
249
279
 
250
280
  it 'should not write the data' do
251
- @states['write'].become('test')
252
- Punch.expects(:write).never.when(@states['write'].is('test'))
281
+ Punch.should.receive(:write).never
253
282
  run_command('in')
254
283
  end
255
284
  end
256
285
  end
257
286
 
258
287
  describe "when the command is 'out'" do
259
- before :each do
260
- Punch.stubs(:out)
288
+ before do
289
+ Punch.stub!(:out)
261
290
  end
262
291
 
263
292
  it 'should load punch data' do
264
- Punch.expects(:load)
293
+ Punch.should.receive(:load)
265
294
  run_command('out', @project)
266
295
  end
267
296
 
268
297
  it 'should punch out of the given project' do
269
- Punch.expects(:out).with(@project, {})
298
+ Punch.should.receive(:out).with(@project, {})
270
299
  run_command('out', @project)
271
300
  end
272
301
 
273
302
  it 'should pass a time if specified on the command line (with --time)' do
274
303
  time_option = '2008-08-23 15:39'
275
304
  time = Time.local(2008, 8, 23, 15, 39)
276
- Punch.expects(:out).with(@project, has_entry(:time => time))
305
+ Punch.should.receive(:out) do |proj, options|
306
+ proj.should == @project
307
+ options[:time].should == time
308
+ end
277
309
  run_command('out', @project, '--time', time_option)
278
310
  end
279
311
 
280
312
  it 'should pass a time if specified on the command line (with --at)' do
281
313
  time_option = '2008-08-23 15:39'
282
314
  time = Time.local(2008, 8, 23, 15, 39)
283
- Punch.expects(:out).with(@project, has_entry(:time => time))
315
+ Punch.should.receive(:out) do |proj, options|
316
+ proj.should == @project
317
+ options[:time].should == time
318
+ end
284
319
  run_command('out', @project, '--at', time_option)
285
320
  end
286
321
 
287
322
  it 'should pass a message if specified on the command line (with --message)' do
288
323
  message = 'Finished doing some stellar work'
289
- Punch.expects(:out).with(@project, has_entry(:message => message))
324
+ Punch.should.receive(:out) do |proj, options|
325
+ proj.should == @project
326
+ options[:message].should == message
327
+ end
290
328
  run_command('out', @project, '--message', message)
291
329
  end
292
330
 
293
331
  it 'should pass a message if specified on the command line (with -m)' do
294
332
  message = 'Finished doing some stellar work'
295
- Punch.expects(:out).with(@project, has_entry(:message => message))
333
+ Punch.should.receive(:out) do |proj, options|
334
+ proj.should == @project
335
+ options[:message].should == message
336
+ end
296
337
  run_command('out', @project, '-m', message)
297
338
  end
298
339
 
299
340
  describe 'if no project given' do
300
341
  it 'should punch out of all projects' do
301
- Punch.expects(:out).with(nil, {})
342
+ Punch.should.receive(:out).with(nil, {})
302
343
  run_command('out')
303
344
  end
304
345
 
305
346
  it 'should pass a time if specified on the command line (with --time)' do
306
347
  time_option = '2008-08-23 15:39'
307
348
  time = Time.local(2008, 8, 23, 15, 39)
308
- Punch.expects(:out).with(nil, has_entry(:time => time))
349
+ Punch.should.receive(:out) do |proj, options|
350
+ proj.should.be.nil
351
+ options[:time].should == time
352
+ end
309
353
  run_command('out', '--time', time_option)
310
354
  end
311
355
 
312
356
  it 'should pass a time if specified on the command line (with --at)' do
313
357
  time_option = '2008-08-23 15:39'
314
358
  time = Time.local(2008, 8, 23, 15, 39)
315
- Punch.expects(:out).with(nil, has_entry(:time => time))
359
+ Punch.should.receive(:out) do |proj, options|
360
+ proj.should.be.nil
361
+ options[:time].should == time
362
+ end
316
363
  run_command('out', '--at', time_option)
317
364
  end
318
365
 
319
366
  it 'should pass a message if specified on the command line (with --message)' do
320
367
  message = 'Finished doing some stellar work'
321
- Punch.expects(:out).with(nil, has_entry(:message => message))
368
+ Punch.should.receive(:out) do |proj, options|
369
+ proj.should.be.nil
370
+ options[:message].should == message
371
+ end
322
372
  run_command('out', '--message', message)
323
373
  end
324
374
 
325
375
  it 'should pass a message if specified on the command line (with -m)' do
326
376
  message = 'Finished doing some stellar work'
327
- Punch.expects(:out).with(nil, has_entry(:message => message))
377
+ Punch.should.receive(:out) do |proj, options|
378
+ proj.should.be.nil
379
+ options[:message].should == message
380
+ end
328
381
  run_command('out', '-m', message)
329
382
  end
330
383
  end
331
384
 
332
385
  describe 'when punched out successfully' do
333
- before :each do
334
- Punch.stubs(:out).returns(true)
386
+ before do
387
+ Punch.stub!(:out).and_return(true)
335
388
  end
336
389
 
337
390
  it 'should write the data' do
338
- Punch.expects(:write)
391
+ Punch.should.receive(:write)
339
392
  run_command('out', @project)
340
393
  end
341
394
 
342
395
  it 'should not print anything' do
343
- @states['puts'].become('test')
344
- self.expects(:puts).never.when(@states['puts'].is('test'))
396
+ self.should.receive(:puts).never
345
397
  run_command('out', @project)
346
398
  end
347
399
 
348
400
  describe 'and no project given' do
349
401
  it 'should not print anything' do
350
- @states['puts'].become('test')
351
- self.expects(:puts).never.when(@states['puts'].is('test'))
402
+ self.should.receive(:puts).never
352
403
  run_command('out')
353
404
  end
354
405
  end
355
406
  end
356
407
 
357
408
  describe 'when not punched out successfully' do
358
- before :each do
359
- Punch.stubs(:out).returns(false)
409
+ before do
410
+ Punch.stub!(:out).and_return(false)
360
411
  end
361
412
 
362
413
  it 'should not write the data' do
363
- @states['write'].become('test')
364
- Punch.expects(:write).never.when(@states['write'].is('test'))
414
+ Punch.should.receive(:write).never
365
415
  run_command('out', @project)
366
416
  end
367
417
 
368
418
  it 'should print a message' do
369
- self.expects(:puts).with(regexp_matches(/already.+out/i))
419
+ self.should.receive(:puts) do |output|
420
+ output.should.match(/already.+out/i)
421
+ end
370
422
  run_command('out', @project)
371
423
  end
372
424
 
373
425
  describe 'and no project given' do
374
426
  it 'should print a message' do
375
- self.expects(:puts).with(regexp_matches(/already.+out/i))
427
+ self.should.receive(:puts) do |output|
428
+ output.should.match(/already.+out/i)
429
+ end
376
430
  run_command('out')
377
431
  end
378
432
  end
@@ -380,184 +434,207 @@ describe 'punch command' do
380
434
  end
381
435
 
382
436
  describe "when the command is 'delete'" do
383
- before :each do
384
- @states['delete'] = states('delete').starts_as('setup')
385
- Punch.stubs(:delete).when(@states['write'].is('setup'))
437
+ before do
438
+ Punch.stub!(:delete)
386
439
  end
387
440
 
388
441
  it 'should load punch data' do
389
- Punch.expects(:load)
442
+ Punch.should.receive(:load)
390
443
  run_command('delete', @project)
391
444
  end
392
445
 
393
446
  it 'should delete the given project' do
394
- Punch.stubs(:write)
395
- Punch.expects(:delete).with(@project)
447
+ Punch.stub!(:write)
448
+ Punch.should.receive(:delete).with(@project)
396
449
  run_command('delete', @project)
397
450
  end
398
451
 
399
452
  it 'should output the result' do
400
453
  result = 'result'
401
- Punch.stubs(:delete).returns(result)
402
- self.expects(:puts).with(result.inspect)
454
+ Punch.stub!(:delete).and_return(result)
455
+ self.should.receive(:puts).with(result.inspect)
403
456
  run_command('delete', @project)
404
457
  end
405
458
 
406
459
  describe 'when deleted successfully' do
407
460
  it 'should write the data' do
408
- Punch.stubs(:delete).returns(true)
409
- Punch.expects(:write)
461
+ Punch.stub!(:delete).and_return(true)
462
+ Punch.should.receive(:write)
410
463
  run_command('delete', @project)
411
464
  end
412
465
  end
413
466
 
414
467
  describe 'when not deleted successfully' do
415
468
  it 'should not write the data' do
416
- @states['write'].become('test')
417
- Punch.stubs(:delete).returns(nil)
418
- Punch.expects(:write).never.when(@states['write'].is('test'))
469
+ Punch.stub!(:delete).and_return(nil)
470
+ Punch.should.receive(:write).never
419
471
  run_command('delete', @project)
420
472
  end
421
473
  end
422
474
 
423
475
  describe 'when no project given' do
424
476
  it 'should display an error message' do
425
- self.expects(:puts).with(regexp_matches(/project.+require/i))
477
+ self.should.receive(:puts) do |output|
478
+ output.should.match(/project.+require/i)
479
+ end
426
480
  run_command('delete')
427
481
  end
428
482
 
429
483
  it 'should not delete' do
430
- @states['delete'].become('test')
431
- Punch.stubs(:write)
432
- Punch.expects(:delete).never.when(@states['delete'].is('test'))
484
+ Punch.stub!(:write)
485
+ Punch.should.receive(:delete).never
433
486
  run_command('delete')
434
487
  end
435
488
 
436
489
  it 'should not write the data' do
437
- @states['write'].become('test')
438
- Punch.expects(:write).never.when(@states['write'].is('test'))
490
+ Punch.should.receive(:write).never
439
491
  run_command('delete')
440
492
  end
441
493
  end
442
494
  end
443
495
 
444
496
  describe "when the command is 'log'" do
445
- before :each do
446
- @states['log'] = states('log').starts_as('setup')
447
- Punch.stubs(:log).when(@states['log'].is('setup'))
497
+ before do
498
+ Punch.stub!(:log)
448
499
  @message = 'log message'
449
500
  end
450
501
 
451
502
  it 'should load punch data' do
452
- Punch.expects(:load)
503
+ Punch.should.receive(:load)
453
504
  run_command('log', @project, @message)
454
505
  end
455
506
 
456
507
  it 'should log a message for the given project' do
457
- Punch.stubs(:write)
458
- Punch.expects(:log).with(@project, @message)
508
+ Punch.stub!(:write)
509
+ Punch.should.receive(:log).with(@project, @message, {})
459
510
  run_command('log', @project, @message)
460
511
  end
461
512
 
513
+ it 'should pass a time if specified on the command line (with --time)' do
514
+ time_option = '2008-08-23 15:39'
515
+ time = Time.local(2008, 8, 23, 15, 39)
516
+ Punch.should.receive(:log) do |proj, msg, options|
517
+ proj.should == @project
518
+ msg.should == @message
519
+ options[:time].should == time
520
+ end
521
+ run_command('log', @project, @message, '--time', time_option)
522
+ end
523
+
524
+ it 'should pass a time if specified on the command line (with --at)' do
525
+ time_option = '2008-08-23 15:39'
526
+ time = Time.local(2008, 8, 23, 15, 39)
527
+ Punch.should.receive(:log) do |proj, msg, options|
528
+ proj.should == @project
529
+ msg.should == @message
530
+ options[:time].should == time
531
+ end
532
+ run_command('log', @project, @message, '--at', time_option)
533
+ end
534
+
462
535
  describe 'when logged successfully' do
463
- before :each do
464
- Punch.stubs(:log).returns(true)
536
+ before do
537
+ Punch.stub!(:log).and_return(true)
465
538
  end
466
539
 
467
540
  it 'should write the data' do
468
- Punch.expects(:write)
541
+ Punch.should.receive(:write)
469
542
  run_command('log', @project, @message)
470
543
  end
471
544
 
472
545
  it 'should not print anything' do
473
- @states['puts'].become('test')
474
- self.expects(:puts).never.when(@states['write'].is('test'))
546
+ self.should.receive(:puts).never
475
547
  run_command('log', @project, @message)
476
548
  end
477
549
  end
478
550
 
479
- describe 'when not deleted successfully' do
480
- before :each do
481
- Punch.stubs(:log).returns(false)
551
+ describe 'when not logged successfully' do
552
+ before do
553
+ Punch.stub!(:log).and_return(false)
482
554
  end
483
555
 
484
556
  it 'should not write the data' do
485
- @states['write'].become('test')
486
- Punch.expects(:write).never.when(@states['write'].is('test'))
557
+ Punch.should.receive(:write).never
487
558
  run_command('log', @project, @message)
488
559
  end
489
560
 
490
561
  it 'should print a message' do
491
- self.expects(:puts).with(regexp_matches(/not.+in/i))
562
+ self.should.receive(:puts) do |output|
563
+ output.should.match(/not.+in/i)
564
+ end
492
565
  run_command('log', @project, @message)
493
566
  end
494
567
  end
495
568
 
496
569
  describe 'when no project given' do
497
570
  it 'should display an error message' do
498
- self.expects(:puts).with(regexp_matches(/project.+require/i))
571
+ self.should.receive(:puts) do |output|
572
+ output.should.match(/project.+require/i)
573
+ end
499
574
  run_command('log')
500
575
  end
501
576
 
502
577
  it 'should not log' do
503
- @states['log'].become('test')
504
- Punch.stubs(:write)
505
- Punch.expects(:log).never.when(@states['log'].is('test'))
578
+ Punch.stub!(:write)
579
+ Punch.should.receive(:log).never
506
580
  run_command('log')
507
581
  end
508
582
 
509
583
  it 'should not write the data' do
510
- @states['write'].become('test')
511
- Punch.expects(:write).never.when(@states['write'].is('test'))
584
+ Punch.should.receive(:write).never
512
585
  run_command('log')
513
586
  end
514
587
  end
515
588
 
516
589
  describe 'when no message given' do
517
590
  it 'should display an error message' do
518
- self.expects(:puts).with(regexp_matches(/message.+require/i))
591
+ self.should.receive(:puts) do |output|
592
+ output.should.match(/message.+require/i)
593
+ end
519
594
  run_command('log', @project)
520
595
  end
521
596
 
522
597
  it 'should not log' do
523
- @states['log'].become('test')
524
- Punch.stubs(:write)
525
- Punch.expects(:log).never.when(@states['log'].is('test'))
598
+ Punch.stub!(:write)
599
+ Punch.should.receive(:log).never
526
600
  run_command('log', @project)
527
601
  end
528
602
 
529
603
  it 'should not write the data' do
530
- @states['write'].become('test')
531
- Punch.expects(:write).never.when(@states['write'].is('test'))
604
+ Punch.should.receive(:write).never
532
605
  run_command('log', @project)
533
606
  end
534
607
  end
535
608
  end
536
609
 
537
610
  describe "when the command is 'list'" do
538
- before :each do
539
- Punch.stubs(:list)
611
+ before do
612
+ Punch.stub!(:list)
540
613
  end
541
614
 
542
615
  it 'should load punch data' do
543
- Punch.expects(:load)
616
+ Punch.should.receive(:load)
544
617
  run_command('list', @project)
545
618
  end
546
619
 
547
620
  it 'should get the data for the requested project' do
548
- Punch.expects(:list).with(@project, anything)
621
+ Punch.should.receive(:list) do |proj, _|
622
+ proj.should == @project
623
+ end
549
624
  run_command('list', @project)
550
625
  end
551
626
 
552
627
  it 'should get the data for all projects if none given' do
553
- Punch.expects(:list).with(nil, anything)
628
+ Punch.should.receive(:list) do |proj, _|
629
+ proj.should.be.nil
630
+ end
554
631
  run_command('list')
555
632
  end
556
633
 
557
634
  it 'should output the list data' do
558
635
  result = 'list data'
559
- Punch.stubs(:list).returns(result)
560
- self.expects(:puts).with(result.to_yaml)
636
+ Punch.stub!(:list).and_return(result)
637
+ self.should.receive(:puts).with(result.to_yaml)
561
638
  run_command('list')
562
639
  end
563
640
 
@@ -565,58 +642,70 @@ describe 'punch command' do
565
642
  it "should pass on an 'after' time option given by --after" do
566
643
  time_option = '2008-08-26 09:47'
567
644
  time = Time.local(2008, 8, 26, 9, 47)
568
- Punch.expects(:list).with(@project, has_entry(:after => time))
645
+ Punch.should.receive(:list) do |proj, options|
646
+ proj.should == @project
647
+ options[:after].should == time
648
+ end
569
649
  run_command('list', @project, '--after', time_option)
570
650
  end
571
651
 
572
652
  it "should pass on a 'before' time option given by --before" do
573
653
  time_option = '2008-08-23 15:39'
574
654
  time = Time.local(2008, 8, 23, 15, 39)
575
- Punch.expects(:list).with(@project, has_entry(:before => time))
655
+ Punch.should.receive(:list) do |proj, options|
656
+ proj.should == @project
657
+ options[:before].should == time
658
+ end
576
659
  run_command('list', @project, '--before', time_option)
577
660
  end
578
661
 
579
662
  it 'should handle a time option given as a date' do
580
663
  time_option = '2008-08-23'
581
664
  time = Time.local(2008, 8, 23)
582
- Punch.expects(:list).with(@project, has_entry(:before => time))
665
+ Punch.should.receive(:list) do |proj, options|
666
+ proj.should == @project
667
+ options[:before].should == time
668
+ end
583
669
  run_command('list', @project, '--before', time_option)
584
670
  end
585
671
 
586
672
  it 'should accept time options if no project given' do
587
673
  time_option = '2008-08-26 09:47'
588
674
  time = Time.local(2008, 8, 26, 9, 47)
589
- Punch.expects(:list).with(nil, has_entry(:before => time))
675
+ Punch.should.receive(:list) do |proj, options|
676
+ proj.should.be.nil
677
+ options[:before].should == time
678
+ end
590
679
  run_command('list', '--before', time_option)
591
680
  end
592
681
  end
593
682
 
594
683
  it 'should not write the data' do
595
- @states['write'].become('test')
596
- Punch.expects(:write).never.when(@states['write'].is('test'))
684
+ Punch.should.receive(:write).never
597
685
  run_command('list')
598
686
  end
599
687
  end
600
688
 
601
689
  describe 'when the command is unknown' do
602
690
  it 'should not error' do
603
- lambda { run_command('bunk') }.should_not raise_error
691
+ lambda { run_command('bunk') }.should.not.raise
604
692
  end
605
693
 
606
694
  it 'should print a message' do
607
- self.expects(:puts).with(regexp_matches(/command.+unknown/i))
695
+ self.should.receive(:puts) do |output|
696
+ output.should.match(/command.+unknown/i)
697
+ end
608
698
  run_command('bunk')
609
699
  end
610
700
 
611
701
  it 'should not write the data' do
612
- @states['write'].become('test')
613
- Punch.expects(:write).never.when(@states['write'].is('test'))
702
+ Punch.should.receive(:write).never
614
703
  run_command('bunk')
615
704
  end
616
705
 
617
706
  it 'should not run any punch command' do
618
- [:in, :out, :delete, :status, :total, :log].each do |command|
619
- Punch.expects(command).never
707
+ [:in, :out, :delete, :status, :total, :log, :list].each do |command|
708
+ Punch.should.receive(command).never
620
709
  end
621
710
  run_command('bunk')
622
711
  end