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 +7 -0
- data/Manifest.txt +0 -2
- data/bin/punch +1 -1
- data/config/hoe.rb +2 -2
- data/lib/punch/instance.rb +2 -2
- data/lib/punch/version.rb +1 -1
- data/lib/punch.rb +8 -6
- data/spec/fixnum_spec.rb +1 -1
- data/spec/punch_command_spec.rb +254 -165
- data/spec/punch_instance_spec.rb +109 -62
- data/spec/punch_spec.rb +198 -124
- data/spec/spec_helper.rb +3 -20
- metadata +6 -8
- data/spec/spec.opts +0 -1
- data/tasks/rspec.rake +0 -21
data/spec/punch_instance_spec.rb
CHANGED
@@ -1,18 +1,18 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/spec_helper.rb'
|
2
2
|
|
3
3
|
describe Punch, 'instance' do
|
4
|
-
before
|
4
|
+
before do
|
5
5
|
@project = 'proj'
|
6
6
|
@punch = Punch.new(@project)
|
7
7
|
end
|
8
8
|
|
9
9
|
describe 'when initialized' do
|
10
10
|
it 'should accept a project' do
|
11
|
-
lambda { Punch.new(@project) }.
|
11
|
+
lambda { Punch.new(@project) }.should.not.raise(ArgumentError)
|
12
12
|
end
|
13
13
|
|
14
14
|
it 'should require a project' do
|
15
|
-
lambda { Punch.new }.should
|
15
|
+
lambda { Punch.new }.should.raise(ArgumentError)
|
16
16
|
end
|
17
17
|
|
18
18
|
it 'should save the project for later use' do
|
@@ -21,22 +21,22 @@ describe Punch, 'instance' do
|
|
21
21
|
end
|
22
22
|
|
23
23
|
it 'should give project status' do
|
24
|
-
@punch.should
|
24
|
+
@punch.should.respond_to(:status)
|
25
25
|
end
|
26
26
|
|
27
27
|
describe 'giving project status' do
|
28
|
-
before
|
28
|
+
before do
|
29
29
|
@status = 'status val'
|
30
|
-
Punch.
|
30
|
+
Punch.stub!(:status).and_return(@status)
|
31
31
|
end
|
32
32
|
|
33
33
|
it 'should delegate to the class' do
|
34
|
-
Punch.
|
34
|
+
Punch.should.receive(:status)
|
35
35
|
@punch.status
|
36
36
|
end
|
37
37
|
|
38
38
|
it 'should pass the project when delegating to the class' do
|
39
|
-
Punch.
|
39
|
+
Punch.should.receive(:status).with(@project)
|
40
40
|
@punch.status
|
41
41
|
end
|
42
42
|
|
@@ -46,22 +46,22 @@ describe Punch, 'instance' do
|
|
46
46
|
end
|
47
47
|
|
48
48
|
it 'should indicate whether the project is punched out' do
|
49
|
-
@punch.should
|
49
|
+
@punch.should.respond_to(:out?)
|
50
50
|
end
|
51
51
|
|
52
52
|
describe 'indicating whether the project is punched out' do
|
53
|
-
before
|
53
|
+
before do
|
54
54
|
@out = 'out val'
|
55
|
-
Punch.
|
55
|
+
Punch.stub!(:out?).and_return(@out)
|
56
56
|
end
|
57
57
|
|
58
58
|
it 'should delegate to the class' do
|
59
|
-
Punch.
|
59
|
+
Punch.should.receive(:out?)
|
60
60
|
@punch.out?
|
61
61
|
end
|
62
62
|
|
63
63
|
it 'should pass the project when delegating to the class' do
|
64
|
-
Punch.
|
64
|
+
Punch.should.receive(:out?).with(@project)
|
65
65
|
@punch.out?
|
66
66
|
end
|
67
67
|
|
@@ -71,22 +71,22 @@ describe Punch, 'instance' do
|
|
71
71
|
end
|
72
72
|
|
73
73
|
it 'should indicate whether the project is punched in' do
|
74
|
-
@punch.should
|
74
|
+
@punch.should.respond_to(:in?)
|
75
75
|
end
|
76
76
|
|
77
77
|
describe 'indicating whether the project is punched in' do
|
78
|
-
before
|
78
|
+
before do
|
79
79
|
@in = 'in val'
|
80
|
-
Punch.
|
80
|
+
Punch.stub!(:in?).and_return(@in)
|
81
81
|
end
|
82
82
|
|
83
83
|
it 'should delegate to the class' do
|
84
|
-
Punch.
|
84
|
+
Punch.should.receive(:in?)
|
85
85
|
@punch.in?
|
86
86
|
end
|
87
87
|
|
88
88
|
it 'should pass the project when delegating to the class' do
|
89
|
-
Punch.
|
89
|
+
Punch.should.receive(:in?).with(@project)
|
90
90
|
@punch.in?
|
91
91
|
end
|
92
92
|
|
@@ -96,41 +96,47 @@ describe Punch, 'instance' do
|
|
96
96
|
end
|
97
97
|
|
98
98
|
it 'should punch the project in' do
|
99
|
-
@punch.should
|
99
|
+
@punch.should.respond_to(:in)
|
100
100
|
end
|
101
101
|
|
102
102
|
describe 'punching the project in' do
|
103
|
-
before
|
103
|
+
before do
|
104
104
|
@in = 'in val'
|
105
|
-
Punch.
|
105
|
+
Punch.stub!(:in).and_return(@in)
|
106
106
|
end
|
107
107
|
|
108
108
|
it 'should accept options' do
|
109
|
-
lambda { @punch.in(:time => Time.now) }.
|
109
|
+
lambda { @punch.in(:time => Time.now) }.should.not.raise(ArgumentError)
|
110
110
|
end
|
111
111
|
|
112
112
|
it 'should not require options' do
|
113
|
-
lambda { @punch.in }.
|
113
|
+
lambda { @punch.in }.should.not.raise(ArgumentError)
|
114
114
|
end
|
115
115
|
|
116
116
|
it 'should delegate to the class' do
|
117
|
-
Punch.
|
117
|
+
Punch.should.receive(:in)
|
118
118
|
@punch.in
|
119
119
|
end
|
120
120
|
|
121
121
|
it 'should pass the project when delegating to the class' do
|
122
|
-
Punch.
|
122
|
+
Punch.should.receive(:in) do |proj, _|
|
123
|
+
proj.should == @project
|
124
|
+
end
|
123
125
|
@punch.in
|
124
126
|
end
|
125
127
|
|
126
128
|
it 'should pass the options when delegating to the class' do
|
127
129
|
options = { :time => Time.now }
|
128
|
-
Punch.
|
130
|
+
Punch.should.receive(:in) do |_, opts|
|
131
|
+
opts.should == options
|
132
|
+
end
|
129
133
|
@punch.in(options)
|
130
134
|
end
|
131
135
|
|
132
136
|
it 'should pass an empty hash if no options given' do
|
133
|
-
Punch.
|
137
|
+
Punch.should.receive(:in) do |_, opts|
|
138
|
+
opts.should == {}
|
139
|
+
end
|
134
140
|
@punch.in
|
135
141
|
end
|
136
142
|
|
@@ -140,41 +146,47 @@ describe Punch, 'instance' do
|
|
140
146
|
end
|
141
147
|
|
142
148
|
it 'should punch the project out' do
|
143
|
-
@punch.should
|
149
|
+
@punch.should.respond_to(:out)
|
144
150
|
end
|
145
151
|
|
146
152
|
describe 'punching the project out' do
|
147
|
-
before
|
153
|
+
before do
|
148
154
|
@out = 'out val'
|
149
|
-
Punch.
|
155
|
+
Punch.stub!(:out).and_return(@out)
|
150
156
|
end
|
151
157
|
|
152
158
|
it 'should accept options' do
|
153
|
-
lambda { @punch.out(:time => Time.now) }.
|
159
|
+
lambda { @punch.out(:time => Time.now) }.should.not.raise(ArgumentError)
|
154
160
|
end
|
155
161
|
|
156
162
|
it 'should not require options' do
|
157
|
-
lambda { @punch.out }.
|
163
|
+
lambda { @punch.out }.should.not.raise(ArgumentError)
|
158
164
|
end
|
159
165
|
|
160
166
|
it 'should delegate to the class' do
|
161
|
-
Punch.
|
167
|
+
Punch.should.receive(:out)
|
162
168
|
@punch.out
|
163
169
|
end
|
164
170
|
|
165
171
|
it 'should pass the project when delegating to the class' do
|
166
|
-
Punch.
|
172
|
+
Punch.should.receive(:out) do |proj, _|
|
173
|
+
proj.should == @project
|
174
|
+
end
|
167
175
|
@punch.out
|
168
176
|
end
|
169
177
|
|
170
178
|
it 'should pass the options when delegating to the class' do
|
171
179
|
options = { :time => Time.now }
|
172
|
-
Punch.
|
180
|
+
Punch.should.receive(:out) do |_, opts|
|
181
|
+
opts.should == options
|
182
|
+
end
|
173
183
|
@punch.out(options)
|
174
184
|
end
|
175
185
|
|
176
186
|
it 'should pass an empty hash if no options given' do
|
177
|
-
Punch.
|
187
|
+
Punch.should.receive(:out) do |_, opts|
|
188
|
+
opts.should == {}
|
189
|
+
end
|
178
190
|
@punch.out
|
179
191
|
end
|
180
192
|
|
@@ -184,41 +196,47 @@ describe Punch, 'instance' do
|
|
184
196
|
end
|
185
197
|
|
186
198
|
it 'should list the project data' do
|
187
|
-
@punch.should
|
199
|
+
@punch.should.respond_to(:list)
|
188
200
|
end
|
189
201
|
|
190
202
|
describe 'listing the project data' do
|
191
|
-
before
|
203
|
+
before do
|
192
204
|
@list = 'list val'
|
193
|
-
Punch.
|
205
|
+
Punch.stub!(:list).and_return(@list)
|
194
206
|
end
|
195
207
|
|
196
208
|
it 'should accept options' do
|
197
|
-
lambda { @punch.list(:time => Time.now) }.
|
209
|
+
lambda { @punch.list(:time => Time.now) }.should.not.raise(ArgumentError)
|
198
210
|
end
|
199
211
|
|
200
212
|
it 'should not require options' do
|
201
|
-
lambda { @punch.list }.
|
213
|
+
lambda { @punch.list }.should.not.raise(ArgumentError)
|
202
214
|
end
|
203
215
|
|
204
216
|
it 'should delegate to the class' do
|
205
|
-
Punch.
|
217
|
+
Punch.should.receive(:list)
|
206
218
|
@punch.list
|
207
219
|
end
|
208
220
|
|
209
221
|
it 'should pass the project when delegating to the class' do
|
210
|
-
Punch.
|
222
|
+
Punch.should.receive(:list) do |proj, _|
|
223
|
+
proj.should == @project
|
224
|
+
end
|
211
225
|
@punch.list
|
212
226
|
end
|
213
227
|
|
214
228
|
it 'should pass the options when delegating to the class' do
|
215
229
|
options = { :time => Time.now }
|
216
|
-
Punch.
|
230
|
+
Punch.should.receive(:list) do |_, opts|
|
231
|
+
opts.should == options
|
232
|
+
end
|
217
233
|
@punch.list(options)
|
218
234
|
end
|
219
235
|
|
220
236
|
it 'should pass an empty hash if no options given' do
|
221
|
-
Punch.
|
237
|
+
Punch.should.receive(:list) do |_, opts|
|
238
|
+
opts.should == {}
|
239
|
+
end
|
222
240
|
@punch.list
|
223
241
|
end
|
224
242
|
|
@@ -228,41 +246,47 @@ describe Punch, 'instance' do
|
|
228
246
|
end
|
229
247
|
|
230
248
|
it 'should get the project total' do
|
231
|
-
@punch.should
|
249
|
+
@punch.should.respond_to(:total)
|
232
250
|
end
|
233
251
|
|
234
252
|
describe 'getting the project total' do
|
235
|
-
before
|
253
|
+
before do
|
236
254
|
@total = 'total val'
|
237
|
-
Punch.
|
255
|
+
Punch.stub!(:total).and_return(@total)
|
238
256
|
end
|
239
257
|
|
240
258
|
it 'should accept options' do
|
241
|
-
lambda { @punch.total(:time => Time.now) }.
|
259
|
+
lambda { @punch.total(:time => Time.now) }.should.not.raise(ArgumentError)
|
242
260
|
end
|
243
261
|
|
244
262
|
it 'should not require options' do
|
245
|
-
lambda { @punch.total }.
|
263
|
+
lambda { @punch.total }.should.not.raise(ArgumentError)
|
246
264
|
end
|
247
265
|
|
248
266
|
it 'should delegate to the class' do
|
249
|
-
Punch.
|
267
|
+
Punch.should.receive(:total)
|
250
268
|
@punch.total
|
251
269
|
end
|
252
270
|
|
253
271
|
it 'should pass the project when delegating to the class' do
|
254
|
-
Punch.
|
272
|
+
Punch.should.receive(:total) do |proj, _|
|
273
|
+
proj.should == @project
|
274
|
+
end
|
255
275
|
@punch.total
|
256
276
|
end
|
257
277
|
|
258
278
|
it 'should pass the options when delegating to the class' do
|
259
279
|
options = { :time => Time.now }
|
260
|
-
Punch.
|
280
|
+
Punch.should.receive(:total) do |_, opts|
|
281
|
+
opts.should == options
|
282
|
+
end
|
261
283
|
@punch.total(options)
|
262
284
|
end
|
263
285
|
|
264
286
|
it 'should pass an empty hash if no options given' do
|
265
|
-
Punch.
|
287
|
+
Punch.should.receive(:total) do |_, opts|
|
288
|
+
opts.should == {}
|
289
|
+
end
|
266
290
|
@punch.total
|
267
291
|
end
|
268
292
|
|
@@ -272,36 +296,59 @@ describe Punch, 'instance' do
|
|
272
296
|
end
|
273
297
|
|
274
298
|
it 'should log information about the project' do
|
275
|
-
@punch.should
|
299
|
+
@punch.should.respond_to(:log)
|
276
300
|
end
|
277
301
|
|
278
302
|
describe 'logging information about the project' do
|
279
|
-
before
|
303
|
+
before do
|
280
304
|
@log = 'log val'
|
281
305
|
@message = 'some log message'
|
282
|
-
Punch.
|
306
|
+
Punch.stub!(:log).and_return(@log)
|
283
307
|
end
|
284
308
|
|
285
309
|
it 'should accept a log message' do
|
286
|
-
lambda { @punch.log(@message) }.
|
310
|
+
lambda { @punch.log(@message) }.should.not.raise(ArgumentError)
|
287
311
|
end
|
288
312
|
|
289
313
|
it 'should require a log message' do
|
290
|
-
lambda { @punch.log }.should
|
314
|
+
lambda { @punch.log }.should.raise(ArgumentError)
|
315
|
+
end
|
316
|
+
|
317
|
+
it 'should accept options' do
|
318
|
+
lambda { @punch.log(@message, :time => Time.now) }.should.not.raise(ArgumentError)
|
291
319
|
end
|
292
320
|
|
293
321
|
it 'should delegate to the class' do
|
294
|
-
Punch.
|
322
|
+
Punch.should.receive(:log)
|
295
323
|
@punch.log(@message)
|
296
324
|
end
|
297
325
|
|
298
326
|
it 'should pass the project when delegating to the class' do
|
299
|
-
Punch.
|
327
|
+
Punch.should.receive(:log) do |proj, _, _|
|
328
|
+
proj.should == @project
|
329
|
+
end
|
300
330
|
@punch.log(@message)
|
301
331
|
end
|
302
332
|
|
303
333
|
it 'should pass the message when delegating to the class' do
|
304
|
-
Punch.
|
334
|
+
Punch.should.receive(:log) do |_, msg, _|
|
335
|
+
msg.should == @message
|
336
|
+
end
|
337
|
+
@punch.log(@message)
|
338
|
+
end
|
339
|
+
|
340
|
+
it 'should pass the options when delegating to the class' do
|
341
|
+
options = { :time => Time.now }
|
342
|
+
Punch.should.receive(:log) do |_, _, opts|
|
343
|
+
opts.should == options
|
344
|
+
end
|
345
|
+
@punch.log(@message, options)
|
346
|
+
end
|
347
|
+
|
348
|
+
it 'should pass an empty hash if no options given' do
|
349
|
+
Punch.should.receive(:log) do |_, _, opts|
|
350
|
+
opts.should == {}
|
351
|
+
end
|
305
352
|
@punch.log(@message)
|
306
353
|
end
|
307
354
|
|
data/spec/punch_spec.rb
CHANGED
@@ -2,11 +2,11 @@ require File.dirname(__FILE__) + '/spec_helper.rb'
|
|
2
2
|
|
3
3
|
describe Punch do
|
4
4
|
it 'should load data' do
|
5
|
-
Punch.should
|
5
|
+
Punch.should.respond_to(:load)
|
6
6
|
end
|
7
7
|
|
8
8
|
describe 'when loading data' do
|
9
|
-
before
|
9
|
+
before do
|
10
10
|
@data = <<-EOD
|
11
11
|
---
|
12
12
|
rip:
|
@@ -30,7 +30,7 @@ describe Punch do
|
|
30
30
|
total: "00:55:17"
|
31
31
|
in: 2008-05-19T11:23:35.00-05:00
|
32
32
|
EOD
|
33
|
-
File.
|
33
|
+
File.stub!(:read).and_return(@data)
|
34
34
|
|
35
35
|
Punch.instance_eval do
|
36
36
|
class << self
|
@@ -42,7 +42,7 @@ describe Punch do
|
|
42
42
|
end
|
43
43
|
|
44
44
|
it 'should read the ~/.punch.yml file' do
|
45
|
-
File.
|
45
|
+
File.should.receive(:read).with(File.expand_path('~/.punch.yml')).and_return(@data)
|
46
46
|
Punch.load
|
47
47
|
end
|
48
48
|
|
@@ -57,11 +57,11 @@ describe Punch do
|
|
57
57
|
end
|
58
58
|
|
59
59
|
describe 'and is empty' do
|
60
|
-
before
|
61
|
-
File.
|
60
|
+
before do
|
61
|
+
File.stub!(:read).and_return('')
|
62
62
|
end
|
63
63
|
|
64
|
-
it 'should
|
64
|
+
it 'should set the data to an empty hash' do
|
65
65
|
Punch.load
|
66
66
|
Punch.data.should == {}
|
67
67
|
end
|
@@ -73,8 +73,8 @@ describe Punch do
|
|
73
73
|
end
|
74
74
|
|
75
75
|
describe 'when no file is found' do
|
76
|
-
before
|
77
|
-
File.
|
76
|
+
before do
|
77
|
+
File.stub!(:read).and_raise(Errno::ENOENT)
|
78
78
|
end
|
79
79
|
|
80
80
|
it 'should set the data to an empty hash' do
|
@@ -82,7 +82,7 @@ describe Punch do
|
|
82
82
|
Punch.data.should == {}
|
83
83
|
end
|
84
84
|
|
85
|
-
it 'should return
|
85
|
+
it 'should return true' do
|
86
86
|
Punch.load.should == true
|
87
87
|
end
|
88
88
|
end
|
@@ -102,14 +102,14 @@ describe Punch do
|
|
102
102
|
end
|
103
103
|
|
104
104
|
it 'should reset itself' do
|
105
|
-
Punch.should
|
105
|
+
Punch.should.respond_to(:reset)
|
106
106
|
end
|
107
107
|
|
108
108
|
describe 'when resetting itself' do
|
109
|
-
before
|
109
|
+
before do
|
110
110
|
Punch.instance_eval do
|
111
111
|
class << self
|
112
|
-
public :data
|
112
|
+
public :data=
|
113
113
|
end
|
114
114
|
end
|
115
115
|
end
|
@@ -117,18 +117,18 @@ describe Punch do
|
|
117
117
|
it 'should set its data to nil' do
|
118
118
|
Punch.data = { 'proj' => 'lots of stuff here' }
|
119
119
|
Punch.reset
|
120
|
-
Punch.instance_variable_get('@data').should
|
120
|
+
Punch.instance_variable_get('@data').should.be.nil
|
121
121
|
end
|
122
122
|
end
|
123
123
|
|
124
124
|
it 'should write data' do
|
125
|
-
Punch.should
|
125
|
+
Punch.should.respond_to(:write)
|
126
126
|
end
|
127
127
|
|
128
128
|
describe 'when writing data' do
|
129
|
-
before
|
130
|
-
@file =
|
131
|
-
File.
|
129
|
+
before do
|
130
|
+
@file = mock('file')
|
131
|
+
File.stub!(:open).and_yield(@file)
|
132
132
|
@data = { 'proj' => 'data goes here' }
|
133
133
|
|
134
134
|
Punch.instance_eval do
|
@@ -140,22 +140,22 @@ describe Punch do
|
|
140
140
|
end
|
141
141
|
|
142
142
|
it 'should open the data file for writing' do
|
143
|
-
File.
|
143
|
+
File.should.receive(:open).with(File.expand_path('~/.punch.yml'), 'w')
|
144
144
|
Punch.write
|
145
145
|
end
|
146
146
|
|
147
147
|
it 'should write the data to the file in YAML form' do
|
148
|
-
@file.
|
148
|
+
@file.should.receive(:puts).with(@data.to_yaml)
|
149
149
|
Punch.write
|
150
150
|
end
|
151
151
|
end
|
152
152
|
|
153
153
|
it 'should give project status' do
|
154
|
-
Punch.should
|
154
|
+
Punch.should.respond_to(:status)
|
155
155
|
end
|
156
156
|
|
157
157
|
describe "giving a project's status" do
|
158
|
-
before
|
158
|
+
before do
|
159
159
|
@now = Time.now
|
160
160
|
@projects = { 'out' => 'test-o', 'in' => 'testshank' }
|
161
161
|
@data = {
|
@@ -172,11 +172,11 @@ describe Punch do
|
|
172
172
|
end
|
173
173
|
|
174
174
|
it 'should accept a project name' do
|
175
|
-
lambda { Punch.status('proj') }.
|
175
|
+
lambda { Punch.status('proj') }.should.not.raise(ArgumentError)
|
176
176
|
end
|
177
177
|
|
178
178
|
it 'should not require a project name' do
|
179
|
-
lambda { Punch.status }.
|
179
|
+
lambda { Punch.status }.should.not.raise(ArgumentError)
|
180
180
|
end
|
181
181
|
|
182
182
|
it "should return 'out' if the project is currently punched out" do
|
@@ -188,14 +188,14 @@ describe Punch do
|
|
188
188
|
end
|
189
189
|
|
190
190
|
it 'should return nil if the project does not exist' do
|
191
|
-
Punch.status('other project').should
|
191
|
+
Punch.status('other project').should.be.nil
|
192
192
|
end
|
193
193
|
|
194
194
|
it 'should return nil if the project has no time data' do
|
195
195
|
project = 'empty project'
|
196
196
|
@data[project] = []
|
197
197
|
Punch.data = @data
|
198
|
-
Punch.status(project).should
|
198
|
+
Punch.status(project).should.be.nil
|
199
199
|
end
|
200
200
|
|
201
201
|
it 'should use the last time entry for the status' do
|
@@ -213,89 +213,89 @@ describe Punch do
|
|
213
213
|
end
|
214
214
|
|
215
215
|
it 'should indicate whether a project is punched out' do
|
216
|
-
Punch.should
|
216
|
+
Punch.should.respond_to(:out?)
|
217
217
|
end
|
218
218
|
|
219
219
|
describe 'indicating whether a project is punched out' do
|
220
|
-
before
|
220
|
+
before do
|
221
221
|
@project = 'testola'
|
222
222
|
end
|
223
223
|
|
224
224
|
it 'should accept a project name' do
|
225
|
-
lambda { Punch.out?('proj') }.
|
225
|
+
lambda { Punch.out?('proj') }.should.not.raise(ArgumentError)
|
226
226
|
end
|
227
227
|
|
228
228
|
it 'should require a project name' do
|
229
|
-
lambda { Punch.out? }.should
|
229
|
+
lambda { Punch.out? }.should.raise(ArgumentError)
|
230
230
|
end
|
231
231
|
|
232
232
|
it "should get the project's status" do
|
233
|
-
Punch.
|
233
|
+
Punch.should.receive(:status).with(@project)
|
234
234
|
Punch.out?(@project)
|
235
235
|
end
|
236
236
|
|
237
237
|
it "should return true if the project's status is 'out'" do
|
238
|
-
Punch.
|
238
|
+
Punch.stub!(:status).and_return('out')
|
239
239
|
Punch.out?(@project).should == true
|
240
240
|
end
|
241
241
|
|
242
242
|
it "should return false if the project's status is 'in'" do
|
243
|
-
Punch.
|
243
|
+
Punch.stub!(:status).and_return('in')
|
244
244
|
Punch.out?(@project).should == false
|
245
245
|
end
|
246
246
|
|
247
247
|
it "should return true if the project's status is nil" do
|
248
|
-
Punch.
|
248
|
+
Punch.stub!(:status).and_return(nil)
|
249
249
|
Punch.out?(@project).should == true
|
250
250
|
end
|
251
251
|
end
|
252
252
|
|
253
253
|
it 'should indicate whether a project is punched in' do
|
254
|
-
Punch.should
|
254
|
+
Punch.should.respond_to(:in?)
|
255
255
|
end
|
256
256
|
|
257
257
|
describe 'indicating whether a project is punched in' do
|
258
|
-
before
|
258
|
+
before do
|
259
259
|
@project = 'testola'
|
260
260
|
end
|
261
261
|
|
262
262
|
it 'should accept a project name' do
|
263
|
-
lambda { Punch.in?('proj') }.
|
263
|
+
lambda { Punch.in?('proj') }.should.not.raise(ArgumentError)
|
264
264
|
end
|
265
265
|
|
266
266
|
it 'should require a project name' do
|
267
|
-
lambda { Punch.in? }.should
|
267
|
+
lambda { Punch.in? }.should.raise(ArgumentError)
|
268
268
|
end
|
269
269
|
|
270
270
|
it "should get the project's status" do
|
271
|
-
Punch.
|
271
|
+
Punch.should.receive(:status).with(@project)
|
272
272
|
Punch.in?(@project)
|
273
273
|
end
|
274
274
|
|
275
275
|
it "should return false if the project's status is 'out'" do
|
276
|
-
Punch.
|
276
|
+
Punch.stub!(:status).and_return('out')
|
277
277
|
Punch.in?(@project).should == false
|
278
278
|
end
|
279
279
|
|
280
280
|
it "should return true if the project's status is 'in'" do
|
281
|
-
Punch.
|
281
|
+
Punch.stub!(:status).and_return('in')
|
282
282
|
Punch.in?(@project).should == true
|
283
283
|
end
|
284
284
|
|
285
285
|
it "should return false if the project's status is nil" do
|
286
|
-
Punch.
|
286
|
+
Punch.stub!(:status).and_return(nil)
|
287
287
|
Punch.in?(@project).should == false
|
288
288
|
end
|
289
289
|
end
|
290
290
|
|
291
291
|
it 'should punch a project in' do
|
292
|
-
Punch.should
|
292
|
+
Punch.should.respond_to(:in)
|
293
293
|
end
|
294
294
|
|
295
295
|
describe 'punching a project in' do
|
296
|
-
before
|
296
|
+
before do
|
297
297
|
@now = Time.now
|
298
|
-
Time.
|
298
|
+
Time.stub!(:now).and_return(@now)
|
299
299
|
@project = 'test project'
|
300
300
|
@data = { @project => [ {'in' => @now - 50, 'out' => @now - 25} ] }
|
301
301
|
|
@@ -308,19 +308,19 @@ describe Punch do
|
|
308
308
|
end
|
309
309
|
|
310
310
|
it 'should accept a project name' do
|
311
|
-
lambda { Punch.in('proj') }.
|
311
|
+
lambda { Punch.in('proj') }.should.not.raise(ArgumentError)
|
312
312
|
end
|
313
313
|
|
314
314
|
it 'should require a project name' do
|
315
|
-
lambda { Punch.in }.should
|
315
|
+
lambda { Punch.in }.should.raise(ArgumentError)
|
316
316
|
end
|
317
317
|
|
318
318
|
it 'should accept options' do
|
319
|
-
lambda { Punch.in('proj', :time => Time.now) }.
|
319
|
+
lambda { Punch.in('proj', :time => Time.now) }.should.not.raise(ArgumentError)
|
320
320
|
end
|
321
321
|
|
322
322
|
describe 'when the project is already punched in' do
|
323
|
-
before
|
323
|
+
before do
|
324
324
|
@data = { @project => [ {'in' => @now - 50, 'out' => @now - 25}, {'in' => @now - 5} ] }
|
325
325
|
Punch.data = @data
|
326
326
|
end
|
@@ -348,8 +348,7 @@ describe Punch do
|
|
348
348
|
end
|
349
349
|
|
350
350
|
it 'should log a message about punch-in time' do
|
351
|
-
time
|
352
|
-
Punch.expects(:log).with(@project, "punch in @ #{time}")
|
351
|
+
Punch.should.receive(:log).with(@project, 'punch in', :time => @now)
|
353
352
|
Punch.in(@project)
|
354
353
|
end
|
355
354
|
|
@@ -361,19 +360,26 @@ describe Punch do
|
|
361
360
|
|
362
361
|
it 'should log a message using the given time' do
|
363
362
|
time = @now + 75
|
364
|
-
|
365
|
-
Punch.expects(:log).with(@project, "punch in @ #{time_str}")
|
363
|
+
Punch.should.receive(:log).with(@project, 'punch in', :time => time)
|
366
364
|
Punch.in(@project, :time => time)
|
367
365
|
end
|
368
366
|
|
369
367
|
it 'should log an additional message if given' do
|
370
|
-
Punch.
|
368
|
+
Punch.stub!(:log) # for the time-based message
|
371
369
|
message = 'working on some stuff'
|
372
|
-
Punch.
|
370
|
+
Punch.should.receive(:log).with(@project, message, :time => @now)
|
373
371
|
Punch.in(@project, :message => message)
|
374
372
|
end
|
375
373
|
|
376
|
-
it
|
374
|
+
it 'should log the additional message with the given time' do
|
375
|
+
Punch.stub!(:log) # for the time-based message
|
376
|
+
time = @now + 75
|
377
|
+
message = 'working on some stuff'
|
378
|
+
Punch.should.receive(:log).with(@project, message, :time => time)
|
379
|
+
Punch.in(@project, :message => message, :time => time)
|
380
|
+
end
|
381
|
+
|
382
|
+
it 'should allow the different time to be specified using :at' do
|
377
383
|
time = @now + 50
|
378
384
|
Punch.in(@project, :at => time)
|
379
385
|
Punch.data[@project].last['in'].should == time
|
@@ -385,13 +391,13 @@ describe Punch do
|
|
385
391
|
end
|
386
392
|
|
387
393
|
describe 'when the project does not yet exist' do
|
388
|
-
before
|
394
|
+
before do
|
389
395
|
@project = 'non-existent project'
|
390
396
|
end
|
391
397
|
|
392
398
|
it 'should create the project' do
|
393
399
|
Punch.in(@project)
|
394
|
-
Punch.data.should
|
400
|
+
Punch.data.should.include(@project)
|
395
401
|
end
|
396
402
|
|
397
403
|
it 'should add a time entry to the project data' do
|
@@ -405,8 +411,7 @@ describe Punch do
|
|
405
411
|
end
|
406
412
|
|
407
413
|
it 'should log a message about punch-in time' do
|
408
|
-
time
|
409
|
-
Punch.expects(:log).with(@project, "punch in @ #{time}")
|
414
|
+
Punch.should.receive(:log).with(@project, 'punch in', :time => @now)
|
410
415
|
Punch.in(@project)
|
411
416
|
end
|
412
417
|
|
@@ -418,11 +423,31 @@ describe Punch do
|
|
418
423
|
|
419
424
|
it 'should log a message using the given time' do
|
420
425
|
time = @now + 75
|
421
|
-
|
422
|
-
Punch.expects(:log).with(@project, "punch in @ #{time_str}")
|
426
|
+
Punch.should.receive(:log).with(@project, 'punch in', :time => time)
|
423
427
|
Punch.in(@project, :time => time)
|
424
428
|
end
|
425
429
|
|
430
|
+
it 'should log an additional message if given' do
|
431
|
+
Punch.stub!(:log) # for the time-based message
|
432
|
+
message = 'working on some stuff'
|
433
|
+
Punch.should.receive(:log).with(@project, message, :time => @now)
|
434
|
+
Punch.in(@project, :message => message)
|
435
|
+
end
|
436
|
+
|
437
|
+
it 'should log the additional message with the given time' do
|
438
|
+
Punch.stub!(:log) # for the time-based message
|
439
|
+
time = @now + 75
|
440
|
+
message = 'working on some stuff'
|
441
|
+
Punch.should.receive(:log).with(@project, message, :time => time)
|
442
|
+
Punch.in(@project, :message => message, :time => time)
|
443
|
+
end
|
444
|
+
|
445
|
+
it 'should allow the different time to be specified using :at' do
|
446
|
+
time = @now + 50
|
447
|
+
Punch.in(@project, :at => time)
|
448
|
+
Punch.data[@project].last['in'].should == time
|
449
|
+
end
|
450
|
+
|
426
451
|
it 'should return true' do
|
427
452
|
Punch.in(@project).should == true
|
428
453
|
end
|
@@ -430,13 +455,13 @@ describe Punch do
|
|
430
455
|
end
|
431
456
|
|
432
457
|
it 'should punch a project out' do
|
433
|
-
Punch.should
|
458
|
+
Punch.should.respond_to(:out)
|
434
459
|
end
|
435
460
|
|
436
461
|
describe 'punching a project out' do
|
437
|
-
before
|
462
|
+
before do
|
438
463
|
@now = Time.now
|
439
|
-
Time.
|
464
|
+
Time.stub!(:now).and_return(@now)
|
440
465
|
@project = 'test project'
|
441
466
|
@data = { @project => [ {'in' => @now - 50, 'out' => @now - 25} ] }
|
442
467
|
|
@@ -449,19 +474,19 @@ describe Punch do
|
|
449
474
|
end
|
450
475
|
|
451
476
|
it 'should accept a project name' do
|
452
|
-
lambda { Punch.out('proj') }.
|
477
|
+
lambda { Punch.out('proj') }.should.not.raise(ArgumentError)
|
453
478
|
end
|
454
479
|
|
455
480
|
it 'should not require a project name' do
|
456
|
-
lambda { Punch.out }.
|
481
|
+
lambda { Punch.out }.should.not.raise(ArgumentError)
|
457
482
|
end
|
458
483
|
|
459
484
|
it 'should accept a project name and options' do
|
460
|
-
lambda { Punch.out('proj', :time => Time.now) }.
|
485
|
+
lambda { Punch.out('proj', :time => Time.now) }.should.not.raise(ArgumentError)
|
461
486
|
end
|
462
487
|
|
463
488
|
it 'should accept options without a project name' do
|
464
|
-
lambda { Punch.out(:time => Time.now) }.
|
489
|
+
lambda { Punch.out(:time => Time.now) }.should.not.raise(ArgumentError)
|
465
490
|
end
|
466
491
|
|
467
492
|
describe 'when the project is already punched out' do
|
@@ -477,7 +502,7 @@ describe Punch do
|
|
477
502
|
end
|
478
503
|
|
479
504
|
describe 'when the project is not already punched out' do
|
480
|
-
before
|
505
|
+
before do
|
481
506
|
@data = { @project => [ {'in' => @now - 50} ] }
|
482
507
|
Punch.data = @data
|
483
508
|
end
|
@@ -493,8 +518,7 @@ describe Punch do
|
|
493
518
|
end
|
494
519
|
|
495
520
|
it 'should log a message about punch-out time' do
|
496
|
-
time
|
497
|
-
Punch.expects(:log).with(@project, "punch out @ #{time}")
|
521
|
+
Punch.should.receive(:log).with(@project, 'punch out', :time => @now)
|
498
522
|
Punch.out(@project)
|
499
523
|
end
|
500
524
|
|
@@ -506,19 +530,26 @@ describe Punch do
|
|
506
530
|
|
507
531
|
it 'should log a message using the given time' do
|
508
532
|
time = @now + 75
|
509
|
-
|
510
|
-
Punch.expects(:log).with(@project, "punch out @ #{time_str}")
|
533
|
+
Punch.should.receive(:log).with(@project, 'punch out', :time => time)
|
511
534
|
Punch.out(@project, :time => time)
|
512
535
|
end
|
513
536
|
|
514
537
|
it 'should log an additional message if given' do
|
515
|
-
Punch.
|
538
|
+
Punch.stub!(:log) # for the time-based message
|
516
539
|
message = 'finished working on some stuff'
|
517
|
-
Punch.
|
540
|
+
Punch.should.receive(:log).with(@project, message, :time => @now)
|
518
541
|
Punch.out(@project, :message => message)
|
519
542
|
end
|
520
543
|
|
521
|
-
it
|
544
|
+
it 'should log the additional message with the given time' do
|
545
|
+
Punch.stub!(:log) # for the time-based message
|
546
|
+
time = @now + 75
|
547
|
+
message = 'working on some stuff'
|
548
|
+
Punch.should.receive(:log).with(@project, message, :time => time)
|
549
|
+
Punch.out(@project, :message => message, :time => time)
|
550
|
+
end
|
551
|
+
|
552
|
+
it 'should allow the different time to be specified using :at' do
|
522
553
|
time = @now + 50
|
523
554
|
Punch.out(@project, :at => time)
|
524
555
|
Punch.data[@project].last['out'].should == time
|
@@ -530,7 +561,7 @@ describe Punch do
|
|
530
561
|
end
|
531
562
|
|
532
563
|
describe 'when no project is given' do
|
533
|
-
before
|
564
|
+
before do
|
534
565
|
@projects = ['test project', 'out project', 'other project']
|
535
566
|
@data = {
|
536
567
|
@projects[0] => [ {'in' => @now - 50, 'out' => @now - 25} ],
|
@@ -549,8 +580,8 @@ describe Punch do
|
|
549
580
|
|
550
581
|
it 'should log punch-out messages for all projects being punched out' do
|
551
582
|
time = @now.strftime('%Y-%m-%dT%H:%M:%S%z')
|
552
|
-
Punch.
|
553
|
-
Punch.
|
583
|
+
Punch.should.receive(:log).with(@projects[1], 'punch out', :time => @now)
|
584
|
+
Punch.should.receive(:log).with(@projects[2], 'punch out', :time => @now)
|
554
585
|
Punch.out
|
555
586
|
end
|
556
587
|
|
@@ -564,26 +595,33 @@ describe Punch do
|
|
564
595
|
|
565
596
|
it 'should log messages using the given time' do
|
566
597
|
time = @now + 75
|
567
|
-
|
568
|
-
Punch.
|
569
|
-
Punch.expects(:log).with(@projects[2], "punch out @ #{time_str}")
|
598
|
+
Punch.should.receive(:log).with(@projects[1], 'punch out', :time => time)
|
599
|
+
Punch.should.receive(:log).with(@projects[2], 'punch out', :time => time)
|
570
600
|
Punch.out(:time => time)
|
571
601
|
end
|
572
602
|
|
573
603
|
it 'should log an additional message if given' do
|
574
|
-
Punch.
|
604
|
+
Punch.stub!(:log) # for the time-based messages
|
575
605
|
message = 'finished working on some stuff'
|
576
|
-
Punch.
|
577
|
-
Punch.
|
606
|
+
Punch.should.receive(:log).with(@projects[1], message, :time => @now)
|
607
|
+
Punch.should.receive(:log).with(@projects[2], message, :time => @now)
|
578
608
|
Punch.out(:message => message)
|
579
609
|
end
|
580
610
|
|
611
|
+
it 'should allow the different time to be specified using :at' do
|
612
|
+
time = @now + 50
|
613
|
+
Punch.out(:at => time)
|
614
|
+
Punch.data[@projects[0]].last['out'].should == @now - 25
|
615
|
+
Punch.data[@projects[1]].last['out'].should == time
|
616
|
+
Punch.data[@projects[2]].last['out'].should == time
|
617
|
+
end
|
618
|
+
|
581
619
|
it 'should return true' do
|
582
620
|
Punch.out.should == true
|
583
621
|
end
|
584
622
|
|
585
623
|
describe 'when all projects were already punched out' do
|
586
|
-
before
|
624
|
+
before do
|
587
625
|
@projects = ['test project', 'out project', 'other project']
|
588
626
|
@data = {
|
589
627
|
@projects[0] => [ {'in' => @now - 50, 'out' => @now - 25} ],
|
@@ -607,11 +645,11 @@ describe Punch do
|
|
607
645
|
end
|
608
646
|
|
609
647
|
it 'should delete a project' do
|
610
|
-
Punch.should
|
648
|
+
Punch.should.respond_to(:delete)
|
611
649
|
end
|
612
650
|
|
613
651
|
describe 'deleting a project' do
|
614
|
-
before
|
652
|
+
before do
|
615
653
|
@now = Time.now
|
616
654
|
@project = 'test project'
|
617
655
|
@data = { @project => [ {'in' => @now - 50, 'out' => @now - 25} ] }
|
@@ -625,17 +663,17 @@ describe Punch do
|
|
625
663
|
end
|
626
664
|
|
627
665
|
it 'should accept a project name' do
|
628
|
-
lambda { Punch.delete('proj') }.
|
666
|
+
lambda { Punch.delete('proj') }.should.not.raise(ArgumentError)
|
629
667
|
end
|
630
668
|
|
631
669
|
it 'should require a project name' do
|
632
|
-
lambda { Punch.delete }.should
|
670
|
+
lambda { Punch.delete }.should.raise(ArgumentError)
|
633
671
|
end
|
634
672
|
|
635
673
|
describe 'when the project exists' do
|
636
674
|
it 'should remove the project data' do
|
637
675
|
Punch.delete(@project)
|
638
|
-
Punch.data.
|
676
|
+
Punch.data.should.not.include(@project)
|
639
677
|
end
|
640
678
|
|
641
679
|
it 'should return true' do
|
@@ -644,22 +682,22 @@ describe Punch do
|
|
644
682
|
end
|
645
683
|
|
646
684
|
describe 'when the project does not exist' do
|
647
|
-
before
|
685
|
+
before do
|
648
686
|
@project = 'non-existent project'
|
649
687
|
end
|
650
688
|
|
651
689
|
it 'should return nil' do
|
652
|
-
Punch.delete(@project).should
|
690
|
+
Punch.delete(@project).should.be.nil
|
653
691
|
end
|
654
692
|
end
|
655
693
|
end
|
656
694
|
|
657
695
|
it 'should list project data' do
|
658
|
-
Punch.should
|
696
|
+
Punch.should.respond_to(:list)
|
659
697
|
end
|
660
698
|
|
661
699
|
describe 'listing project data' do
|
662
|
-
before
|
700
|
+
before do
|
663
701
|
@now = Time.now
|
664
702
|
@project = 'test project'
|
665
703
|
@data = { @project => [ {'in' => @now - 5000, 'out' => @now - 2500}, {'in' => @now - 2000, 'out' => @now - 1000}, {'in' => @now - 500, 'out' => @now - 100} ] }
|
@@ -673,15 +711,15 @@ describe Punch do
|
|
673
711
|
end
|
674
712
|
|
675
713
|
it 'should accept a project name' do
|
676
|
-
lambda { Punch.list('proj') }.
|
714
|
+
lambda { Punch.list('proj') }.should.not.raise(ArgumentError)
|
677
715
|
end
|
678
716
|
|
679
717
|
it 'should not require a project name' do
|
680
|
-
lambda { Punch.list }.
|
718
|
+
lambda { Punch.list }.should.not.raise(ArgumentError)
|
681
719
|
end
|
682
720
|
|
683
721
|
it 'should allow options' do
|
684
|
-
lambda { Punch.list('proj', :after => Time.now) }.
|
722
|
+
lambda { Punch.list('proj', :after => Time.now) }.should.not.raise(ArgumentError)
|
685
723
|
end
|
686
724
|
|
687
725
|
describe 'when the project exists' do
|
@@ -702,7 +740,7 @@ describe Punch do
|
|
702
740
|
end
|
703
741
|
|
704
742
|
describe 'and is punched in' do
|
705
|
-
before
|
743
|
+
before do
|
706
744
|
@data[@project].push({ 'in' => @now - 25 })
|
707
745
|
Punch.data = @data
|
708
746
|
end
|
@@ -722,21 +760,21 @@ describe Punch do
|
|
722
760
|
end
|
723
761
|
|
724
762
|
describe 'when the project does not exist' do
|
725
|
-
before
|
763
|
+
before do
|
726
764
|
@project = 'non-existent project'
|
727
765
|
end
|
728
766
|
|
729
767
|
it 'should return nil' do
|
730
|
-
Punch.list(@project).should
|
768
|
+
Punch.list(@project).should.be.nil
|
731
769
|
end
|
732
770
|
|
733
771
|
it 'should return nil if options given' do
|
734
|
-
Punch.list(@project, :after => @now - 500).should
|
772
|
+
Punch.list(@project, :after => @now - 500).should.be.nil
|
735
773
|
end
|
736
774
|
end
|
737
775
|
|
738
776
|
describe 'when no project is given' do
|
739
|
-
before
|
777
|
+
before do
|
740
778
|
@projects = ['test project', 'out project', 'other project']
|
741
779
|
@data = {
|
742
780
|
@projects[0] => [ {'in' => @now - 50, 'out' => @now - 25} ],
|
@@ -763,13 +801,13 @@ describe Punch do
|
|
763
801
|
end
|
764
802
|
|
765
803
|
it 'should get the total time for a project' do
|
766
|
-
Punch.should
|
804
|
+
Punch.should.respond_to(:total)
|
767
805
|
end
|
768
806
|
|
769
807
|
describe 'getting total time for a project' do
|
770
|
-
before
|
808
|
+
before do
|
771
809
|
@now = Time.now
|
772
|
-
Time.
|
810
|
+
Time.stub!(:now).and_return(@now)
|
773
811
|
@project = 'test project'
|
774
812
|
@data = { @project => [ {'in' => @now - 5000, 'out' => @now - 2500}, {'in' => @now - 2000, 'out' => @now - 1000}, {'in' => @now - 500, 'out' => @now - 100} ] }
|
775
813
|
|
@@ -782,15 +820,15 @@ describe Punch do
|
|
782
820
|
end
|
783
821
|
|
784
822
|
it 'should accept a project name' do
|
785
|
-
lambda { Punch.total('proj') }.
|
823
|
+
lambda { Punch.total('proj') }.should.not.raise(ArgumentError)
|
786
824
|
end
|
787
825
|
|
788
826
|
it 'should not require a project name' do
|
789
|
-
lambda { Punch.total }.
|
827
|
+
lambda { Punch.total }.should.not.raise(ArgumentError)
|
790
828
|
end
|
791
829
|
|
792
830
|
it 'should allow options' do
|
793
|
-
lambda { Punch.total('proj', :after => Time.now) }.
|
831
|
+
lambda { Punch.total('proj', :after => Time.now) }.should.not.raise(ArgumentError)
|
794
832
|
end
|
795
833
|
|
796
834
|
describe 'when the project exists' do
|
@@ -815,7 +853,7 @@ describe Punch do
|
|
815
853
|
end
|
816
854
|
|
817
855
|
describe 'and is punched in' do
|
818
|
-
before
|
856
|
+
before do
|
819
857
|
@data[@project].push({ 'in' => @now - 25 })
|
820
858
|
Punch.data = @data
|
821
859
|
end
|
@@ -839,17 +877,17 @@ describe Punch do
|
|
839
877
|
end
|
840
878
|
|
841
879
|
describe 'when the project does not exist' do
|
842
|
-
before
|
880
|
+
before do
|
843
881
|
@project = 'non-existent project'
|
844
882
|
end
|
845
883
|
|
846
884
|
it 'should return nil' do
|
847
|
-
Punch.total(@project).should
|
885
|
+
Punch.total(@project).should.be.nil
|
848
886
|
end
|
849
887
|
end
|
850
888
|
|
851
889
|
describe 'when no project is given' do
|
852
|
-
before
|
890
|
+
before do
|
853
891
|
@projects = ['test project', 'out project', 'other project']
|
854
892
|
@data = {
|
855
893
|
@projects[0] => [ {'in' => @now - 50, 'out' => @now - 25} ],
|
@@ -874,12 +912,13 @@ describe Punch do
|
|
874
912
|
end
|
875
913
|
|
876
914
|
it 'should log information about a project' do
|
877
|
-
Punch.should
|
915
|
+
Punch.should.respond_to(:log)
|
878
916
|
end
|
879
917
|
|
880
918
|
describe 'logging information about a project' do
|
881
|
-
before
|
919
|
+
before do
|
882
920
|
@now = Time.now
|
921
|
+
Time.stub!(:now).and_return(@now)
|
883
922
|
@project = 'test project'
|
884
923
|
@data = { @project => [ {'in' => @now - 50, 'log' => ['some earlier message']} ] }
|
885
924
|
|
@@ -894,19 +933,27 @@ describe Punch do
|
|
894
933
|
end
|
895
934
|
|
896
935
|
it 'should accept a project and message' do
|
897
|
-
lambda { Punch.log('proj', 'some mess') }.
|
936
|
+
lambda { Punch.log('proj', 'some mess') }.should.not.raise(ArgumentError)
|
898
937
|
end
|
899
938
|
|
900
939
|
it 'should require a message' do
|
901
|
-
lambda { Punch.log('proj') }.should
|
940
|
+
lambda { Punch.log('proj') }.should.raise(ArgumentError)
|
902
941
|
end
|
903
942
|
|
904
943
|
it 'should require a project' do
|
905
|
-
lambda { Punch.log }.should
|
944
|
+
lambda { Punch.log }.should.raise(ArgumentError)
|
945
|
+
end
|
946
|
+
|
947
|
+
it 'should accept options' do
|
948
|
+
lambda { Punch.log('proj', 'some mess', :time => Time.now) }.should.not.raise(ArgumentError)
|
949
|
+
end
|
950
|
+
|
951
|
+
it 'should require a project and message even when options are given' do
|
952
|
+
lambda { Punch.log('proj', :time => Time.now) }.should.raise(ArgumentError)
|
906
953
|
end
|
907
954
|
|
908
955
|
it 'should check if the project is punched in' do
|
909
|
-
Punch.
|
956
|
+
Punch.should.receive(:in?).with(@project)
|
910
957
|
Punch.log(@project, @message)
|
911
958
|
end
|
912
959
|
|
@@ -918,7 +965,33 @@ describe Punch do
|
|
918
965
|
|
919
966
|
it 'should use the given message for the log' do
|
920
967
|
Punch.log(@project, @message)
|
921
|
-
Punch.data[@project].last['log'].last.should
|
968
|
+
Punch.data[@project].last['log'].last.should.match(Regexp.new(Regexp.escape(@message)))
|
969
|
+
end
|
970
|
+
|
971
|
+
it 'should add the formatted time to the message' do
|
972
|
+
time = @now.strftime('%Y-%m-%dT%H:%M:%S%z')
|
973
|
+
Punch.log(@project, @message)
|
974
|
+
Punch.data[@project].last['log'].last.should.match(Regexp.new(Regexp.escape(time)))
|
975
|
+
end
|
976
|
+
|
977
|
+
it 'should format the message as "#{message} @ #{time}"' do
|
978
|
+
time = @now.strftime('%Y-%m-%dT%H:%M:%S%z')
|
979
|
+
Punch.log(@project, @message)
|
980
|
+
Punch.data[@project].last['log'].last.should == "#{@message} @ #{time}"
|
981
|
+
end
|
982
|
+
|
983
|
+
it 'should use a different time if given' do
|
984
|
+
time = @now + 50
|
985
|
+
time_str = time.strftime('%Y-%m-%dT%H:%M:%S%z')
|
986
|
+
Punch.log(@project, @message, :time => time)
|
987
|
+
Punch.data[@project].last['log'].last.should == "#{@message} @ #{time_str}"
|
988
|
+
end
|
989
|
+
|
990
|
+
it 'should allow the different time to be specified using :at' do
|
991
|
+
time = @now + 50
|
992
|
+
time_str = time.strftime('%Y-%m-%dT%H:%M:%S%z')
|
993
|
+
Punch.log(@project, @message, :at => time)
|
994
|
+
Punch.data[@project].last['log'].last.should == "#{@message} @ #{time_str}"
|
922
995
|
end
|
923
996
|
|
924
997
|
it 'should return true' do
|
@@ -926,20 +999,21 @@ describe Punch do
|
|
926
999
|
end
|
927
1000
|
|
928
1001
|
describe 'and has no log' do
|
929
|
-
before
|
1002
|
+
before do
|
930
1003
|
@data = { @project => [ {'in' => @now - 50} ] }
|
931
1004
|
Punch.data = @data
|
932
1005
|
end
|
933
1006
|
|
934
1007
|
it 'should create the log' do
|
1008
|
+
time = @now.strftime('%Y-%m-%dT%H:%M:%S%z')
|
935
1009
|
Punch.log(@project, @message)
|
936
|
-
Punch.data[@project].last['log'].should == [@message]
|
1010
|
+
Punch.data[@project].last['log'].should == ["#{@message} @ #{time}"]
|
937
1011
|
end
|
938
1012
|
end
|
939
1013
|
end
|
940
1014
|
|
941
1015
|
describe 'when the project is not punched in' do
|
942
|
-
before
|
1016
|
+
before do
|
943
1017
|
@data = { @project => [ {'in' => @now - 50, 'out' => @now - 25, 'log' => ['some earlier message']} ] }
|
944
1018
|
Punch.data = @data
|
945
1019
|
end
|