one_inch_punch 0.2.2 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,18 +1,18 @@
1
1
  require File.dirname(__FILE__) + '/spec_helper.rb'
2
2
 
3
3
  describe Punch, 'instance' do
4
- before :each do
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) }.should_not raise_error(ArgumentError)
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 raise_error(ArgumentError)
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 respond_to(:status)
24
+ @punch.should.respond_to(:status)
25
25
  end
26
26
 
27
27
  describe 'giving project status' do
28
- before :each do
28
+ before do
29
29
  @status = 'status val'
30
- Punch.stubs(:status).returns(@status)
30
+ Punch.stub!(:status).and_return(@status)
31
31
  end
32
32
 
33
33
  it 'should delegate to the class' do
34
- Punch.expects(:status)
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.expects(:status).with(@project)
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 respond_to(:out?)
49
+ @punch.should.respond_to(:out?)
50
50
  end
51
51
 
52
52
  describe 'indicating whether the project is punched out' do
53
- before :each do
53
+ before do
54
54
  @out = 'out val'
55
- Punch.stubs(:out?).returns(@out)
55
+ Punch.stub!(:out?).and_return(@out)
56
56
  end
57
57
 
58
58
  it 'should delegate to the class' do
59
- Punch.expects(:out?)
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.expects(:out?).with(@project)
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 respond_to(:in?)
74
+ @punch.should.respond_to(:in?)
75
75
  end
76
76
 
77
77
  describe 'indicating whether the project is punched in' do
78
- before :each do
78
+ before do
79
79
  @in = 'in val'
80
- Punch.stubs(:in?).returns(@in)
80
+ Punch.stub!(:in?).and_return(@in)
81
81
  end
82
82
 
83
83
  it 'should delegate to the class' do
84
- Punch.expects(:in?)
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.expects(:in?).with(@project)
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 respond_to(:in)
99
+ @punch.should.respond_to(:in)
100
100
  end
101
101
 
102
102
  describe 'punching the project in' do
103
- before :each do
103
+ before do
104
104
  @in = 'in val'
105
- Punch.stubs(:in).returns(@in)
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) }.should_not raise_error(ArgumentError)
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 }.should_not raise_error(ArgumentError)
113
+ lambda { @punch.in }.should.not.raise(ArgumentError)
114
114
  end
115
115
 
116
116
  it 'should delegate to the class' do
117
- Punch.expects(:in)
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.expects(:in).with(@project, anything)
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.expects(:in).with(anything, options)
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.expects(:in).with(anything, {})
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 respond_to(:out)
149
+ @punch.should.respond_to(:out)
144
150
  end
145
151
 
146
152
  describe 'punching the project out' do
147
- before :each do
153
+ before do
148
154
  @out = 'out val'
149
- Punch.stubs(:out).returns(@out)
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) }.should_not raise_error(ArgumentError)
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 }.should_not raise_error(ArgumentError)
163
+ lambda { @punch.out }.should.not.raise(ArgumentError)
158
164
  end
159
165
 
160
166
  it 'should delegate to the class' do
161
- Punch.expects(:out)
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.expects(:out).with(@project, anything)
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.expects(:out).with(anything, options)
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.expects(:out).with(anything, {})
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 respond_to(:list)
199
+ @punch.should.respond_to(:list)
188
200
  end
189
201
 
190
202
  describe 'listing the project data' do
191
- before :each do
203
+ before do
192
204
  @list = 'list val'
193
- Punch.stubs(:list).returns(@list)
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) }.should_not raise_error(ArgumentError)
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 }.should_not raise_error(ArgumentError)
213
+ lambda { @punch.list }.should.not.raise(ArgumentError)
202
214
  end
203
215
 
204
216
  it 'should delegate to the class' do
205
- Punch.expects(:list)
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.expects(:list).with(@project, anything)
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.expects(:list).with(anything, options)
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.expects(:list).with(anything, {})
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 respond_to(:total)
249
+ @punch.should.respond_to(:total)
232
250
  end
233
251
 
234
252
  describe 'getting the project total' do
235
- before :each do
253
+ before do
236
254
  @total = 'total val'
237
- Punch.stubs(:total).returns(@total)
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) }.should_not raise_error(ArgumentError)
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 }.should_not raise_error(ArgumentError)
263
+ lambda { @punch.total }.should.not.raise(ArgumentError)
246
264
  end
247
265
 
248
266
  it 'should delegate to the class' do
249
- Punch.expects(:total)
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.expects(:total).with(@project, anything)
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.expects(:total).with(anything, options)
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.expects(:total).with(anything, {})
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 respond_to(:log)
299
+ @punch.should.respond_to(:log)
276
300
  end
277
301
 
278
302
  describe 'logging information about the project' do
279
- before :each do
303
+ before do
280
304
  @log = 'log val'
281
305
  @message = 'some log message'
282
- Punch.stubs(:log).returns(@log)
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) }.should_not raise_error(ArgumentError)
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 raise_error(ArgumentError)
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.expects(:log)
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.expects(:log).with(@project, anything)
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.expects(:log).with(anything, @message)
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 respond_to(:load)
5
+ Punch.should.respond_to(:load)
6
6
  end
7
7
 
8
8
  describe 'when loading data' do
9
- before :each do
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.stubs(:read).returns(@data)
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.expects(:read).with(File.expand_path('~/.punch.yml')).returns(@data)
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 :each do
61
- File.stubs(:read).returns('')
60
+ before do
61
+ File.stub!(:read).and_return('')
62
62
  end
63
63
 
64
- it 'should load the data as yaml' do
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 :each do
77
- File.stubs(:read).raises(Errno::ENOENT)
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 false' do
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 respond_to(:reset)
105
+ Punch.should.respond_to(:reset)
106
106
  end
107
107
 
108
108
  describe 'when resetting itself' do
109
- before :each do
109
+ before do
110
110
  Punch.instance_eval do
111
111
  class << self
112
- public :data, :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 be_nil
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 respond_to(:write)
125
+ Punch.should.respond_to(:write)
126
126
  end
127
127
 
128
128
  describe 'when writing data' do
129
- before :each do
130
- @file = stub('file')
131
- File.stubs(:open).yields(@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.expects(:open).with(File.expand_path('~/.punch.yml'), 'w')
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.expects(:puts).with(@data.to_yaml)
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 respond_to(:status)
154
+ Punch.should.respond_to(:status)
155
155
  end
156
156
 
157
157
  describe "giving a project's status" do
158
- before :each do
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') }.should_not raise_error(ArgumentError)
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 }.should_not raise_error(ArgumentError)
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 be_nil
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 be_nil
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 respond_to(:out?)
216
+ Punch.should.respond_to(:out?)
217
217
  end
218
218
 
219
219
  describe 'indicating whether a project is punched out' do
220
- before :each do
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') }.should_not raise_error(ArgumentError)
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 raise_error(ArgumentError)
229
+ lambda { Punch.out? }.should.raise(ArgumentError)
230
230
  end
231
231
 
232
232
  it "should get the project's status" do
233
- Punch.expects(:status).with(@project)
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.stubs(:status).returns('out')
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.stubs(:status).returns('in')
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.stubs(:status).returns(nil)
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 respond_to(:in?)
254
+ Punch.should.respond_to(:in?)
255
255
  end
256
256
 
257
257
  describe 'indicating whether a project is punched in' do
258
- before :each do
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') }.should_not raise_error(ArgumentError)
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 raise_error(ArgumentError)
267
+ lambda { Punch.in? }.should.raise(ArgumentError)
268
268
  end
269
269
 
270
270
  it "should get the project's status" do
271
- Punch.expects(:status).with(@project)
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.stubs(:status).returns('out')
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.stubs(:status).returns('in')
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.stubs(:status).returns(nil)
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 respond_to(:in)
292
+ Punch.should.respond_to(:in)
293
293
  end
294
294
 
295
295
  describe 'punching a project in' do
296
- before :each do
296
+ before do
297
297
  @now = Time.now
298
- Time.stubs(:now).returns(@now)
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') }.should_not raise_error(ArgumentError)
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 raise_error(ArgumentError)
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) }.should_not raise_error(ArgumentError)
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 :each do
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 = @now.strftime('%Y-%m-%dT%H:%M:%S%z')
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
- time_str = time.strftime('%Y-%m-%dT%H:%M:%S%z')
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.stubs(:log) # for the time-based message
368
+ Punch.stub!(:log) # for the time-based message
371
369
  message = 'working on some stuff'
372
- Punch.expects(:log).with(@project, message)
370
+ Punch.should.receive(:log).with(@project, message, :time => @now)
373
371
  Punch.in(@project, :message => message)
374
372
  end
375
373
 
376
- it "should allow the different time to be specified using :at" do
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 :each do
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 have_key(@project)
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 = @now.strftime('%Y-%m-%dT%H:%M:%S%z')
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
- time_str = time.strftime('%Y-%m-%dT%H:%M:%S%z')
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 respond_to(:out)
458
+ Punch.should.respond_to(:out)
434
459
  end
435
460
 
436
461
  describe 'punching a project out' do
437
- before :each do
462
+ before do
438
463
  @now = Time.now
439
- Time.stubs(:now).returns(@now)
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') }.should_not raise_error(ArgumentError)
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 }.should_not raise_error(ArgumentError)
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) }.should_not raise_error(ArgumentError)
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) }.should_not raise_error(ArgumentError)
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 :each do
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 = @now.strftime('%Y-%m-%dT%H:%M:%S%z')
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
- time_str = time.strftime('%Y-%m-%dT%H:%M:%S%z')
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.stubs(:log) # for the time-based message
538
+ Punch.stub!(:log) # for the time-based message
516
539
  message = 'finished working on some stuff'
517
- Punch.expects(:log).with(@project, message)
540
+ Punch.should.receive(:log).with(@project, message, :time => @now)
518
541
  Punch.out(@project, :message => message)
519
542
  end
520
543
 
521
- it "should allow the different time to be specified using :at" do
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 :each do
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.expects(:log).with(@projects[1], "punch out @ #{time}")
553
- Punch.expects(:log).with(@projects[2], "punch out @ #{time}")
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
- time_str = time.strftime('%Y-%m-%dT%H:%M:%S%z')
568
- Punch.expects(:log).with(@projects[1], "punch out @ #{time_str}")
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.stubs(:log) # for the time-based messages
604
+ Punch.stub!(:log) # for the time-based messages
575
605
  message = 'finished working on some stuff'
576
- Punch.expects(:log).with(@projects[1], message)
577
- Punch.expects(:log).with(@projects[2], message)
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 :each do
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 respond_to(:delete)
648
+ Punch.should.respond_to(:delete)
611
649
  end
612
650
 
613
651
  describe 'deleting a project' do
614
- before :each do
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') }.should_not raise_error(ArgumentError)
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 raise_error(ArgumentError)
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.should_not have_key(@project)
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 :each do
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 be_nil
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 respond_to(:list)
696
+ Punch.should.respond_to(:list)
659
697
  end
660
698
 
661
699
  describe 'listing project data' do
662
- before :each do
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') }.should_not raise_error(ArgumentError)
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 }.should_not raise_error(ArgumentError)
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) }.should_not raise_error(ArgumentError)
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 :each do
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 :each do
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 be_nil
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 be_nil
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 :each do
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 respond_to(:total)
804
+ Punch.should.respond_to(:total)
767
805
  end
768
806
 
769
807
  describe 'getting total time for a project' do
770
- before :each do
808
+ before do
771
809
  @now = Time.now
772
- Time.stubs(:now).returns(@now)
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') }.should_not raise_error(ArgumentError)
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 }.should_not raise_error(ArgumentError)
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) }.should_not raise_error(ArgumentError)
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 :each do
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 :each do
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 be_nil
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 :each do
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 respond_to(:log)
915
+ Punch.should.respond_to(:log)
878
916
  end
879
917
 
880
918
  describe 'logging information about a project' do
881
- before :each do
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') }.should_not raise_error(ArgumentError)
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 raise_error(ArgumentError)
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 raise_error(ArgumentError)
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.expects(:in?).with(@project)
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 == @message
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 :each do
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 :each do
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