whenever 0.9.2 → 0.9.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.
@@ -1,345 +1,269 @@
1
- require File.expand_path(File.dirname(__FILE__) + "/../test_helper")
1
+ require 'test_helper'
2
2
 
3
- class OutputDefaultDefinedJobsTest < Test::Unit::TestCase
3
+ class OutputDefaultDefinedJobsTest < Whenever::TestCase
4
4
 
5
5
  # command
6
6
 
7
- context "A plain command with the job template set to nil" do
8
- setup do
9
- @output = Whenever.cron \
10
- <<-file
11
- set :job_template, nil
12
- every 2.hours do
13
- command "blahblah"
14
- end
15
- file
16
- end
7
+ test "A plain command with the job template set to nil" do
8
+ output = Whenever.cron \
9
+ <<-file
10
+ set :job_template, nil
11
+ every 2.hours do
12
+ command "blahblah"
13
+ end
14
+ file
17
15
 
18
- should "output the command" do
19
- assert_match /^.+ .+ .+ .+ blahblah$/, @output
20
- end
16
+ assert_match /^.+ .+ .+ .+ blahblah$/, output
21
17
  end
22
18
 
23
- context "A plain command with no job template set" do
24
- setup do
25
- @output = Whenever.cron \
26
- <<-file
27
- every 2.hours do
28
- command "blahblah"
29
- end
30
- file
31
- end
19
+ test "A plain command with no job template set" do
20
+ output = Whenever.cron \
21
+ <<-file
22
+ every 2.hours do
23
+ command "blahblah"
24
+ end
25
+ file
32
26
 
33
- should "output the command with the default job template" do
34
- assert_match /^.+ .+ .+ .+ \/bin\/bash -l -c 'blahblah'$/, @output
35
- end
27
+ assert_match /^.+ .+ .+ .+ \/bin\/bash -l -c 'blahblah'$/, output
36
28
  end
37
29
 
38
- context "A plain command with a job_template using a normal parameter" do
39
- setup do
40
- @output = Whenever.cron \
41
- <<-file
42
- set :job_template, "/bin/bash -l -c 'cd :path && :job'"
43
- every 2.hours do
44
- set :path, "/tmp"
45
- command "blahblah"
46
- end
47
- file
48
- end
49
-
50
- should "output the command using that job_template" do
51
- assert_match /^.+ .+ .+ .+ \/bin\/bash -l -c 'cd \/tmp \&\& blahblah'$/, @output
52
- end
30
+ test "A plain command with a job_template using a normal parameter" do
31
+ output = Whenever.cron \
32
+ <<-file
33
+ set :job_template, "/bin/bash -l -c 'cd :path && :job'"
34
+ every 2.hours do
35
+ set :path, "/tmp"
36
+ command "blahblah"
37
+ end
38
+ file
39
+
40
+ assert_match /^.+ .+ .+ .+ \/bin\/bash -l -c 'cd \/tmp \&\& blahblah'$/, output
53
41
  end
54
42
 
43
+ test "A plain command that overrides the job_template set" do
44
+ output = Whenever.cron \
45
+ <<-file
46
+ set :job_template, "/bin/bash -l -c ':job'"
47
+ every 2.hours do
48
+ command "blahblah", :job_template => "/bin/sh -l -c ':job'"
49
+ end
50
+ file
55
51
 
56
- context "A plain command that overrides the job_template set" do
57
- setup do
58
- @output = Whenever.cron \
59
- <<-file
60
- set :job_template, "/bin/bash -l -c ':job'"
61
- every 2.hours do
62
- command "blahblah", :job_template => "/bin/sh -l -c ':job'"
63
- end
64
- file
65
- end
66
52
 
67
- should "output the command using that job_template" do
68
- assert_match /^.+ .+ .+ .+ \/bin\/sh -l -c 'blahblah'$/, @output
69
- assert_no_match /bash/, @output
70
- end
53
+ assert_match /^.+ .+ .+ .+ \/bin\/sh -l -c 'blahblah'$/, output
54
+ assert_no_match /bash/, output
71
55
  end
72
56
 
73
- context "A plain command that overrides the job_template set using a parameter" do
74
- setup do
75
- @output = Whenever.cron \
76
- <<-file
77
- set :job_template, "/bin/bash -l -c 'cd :path && :job'"
78
- every 2.hours do
79
- set :path, "/tmp"
80
- command "blahblah", :job_template => "/bin/sh -l -c 'cd :path && :job'"
81
- end
82
- file
83
- end
57
+ test "A plain command that overrides the job_template set using a parameter" do
58
+ output = Whenever.cron \
59
+ <<-file
60
+ set :job_template, "/bin/bash -l -c 'cd :path && :job'"
61
+ every 2.hours do
62
+ set :path, "/tmp"
63
+ command "blahblah", :job_template => "/bin/sh -l -c 'cd :path && :job'"
64
+ end
65
+ file
84
66
 
85
- should "output the command using that job_template" do
86
- assert_match /^.+ .+ .+ .+ \/bin\/sh -l -c 'cd \/tmp && blahblah'$/, @output
87
- assert_no_match /bash/, @output
88
- end
89
- end
90
67
 
91
- context "A plain command that is conditional on default environent and path" do
92
- setup do
93
- Whenever.expects(:path).at_least_once.returns('/what/you/want')
94
- @output = Whenever.cron \
95
- <<-file
96
- set :job_template, nil
97
- if environment == 'production' && path == '/what/you/want'
98
- every 2.hours do
99
- command "blahblah"
100
- end
101
- end
102
- file
103
- end
104
-
105
- should "output the command" do
106
- assert_match /blahblah/, @output
107
- end
68
+ assert_match /^.+ .+ .+ .+ \/bin\/sh -l -c 'cd \/tmp && blahblah'$/, output
69
+ assert_no_match /bash/, output
108
70
  end
109
71
 
110
- # runner
111
-
112
- context "A runner with path set" do
113
- setup do
114
- @output = Whenever.cron \
115
- <<-file
116
- set :job_template, nil
117
- set :path, '/my/path'
72
+ test "A plain command that is conditional on default environent and path" do
73
+ Whenever.expects(:path).at_least_once.returns('/what/you/want')
74
+ output = Whenever.cron \
75
+ <<-file
76
+ set :job_template, nil
77
+ if environment == 'production' && path == '/what/you/want'
118
78
  every 2.hours do
119
- runner 'blahblah'
79
+ command "blahblah"
120
80
  end
121
- file
122
- end
81
+ end
82
+ file
123
83
 
124
- should "output the runner using that path" do
125
- assert_match two_hours + %( cd /my/path && script/runner -e production 'blahblah'), @output
126
- end
84
+ assert_match /blahblah/, output
127
85
  end
128
86
 
129
- context "A runner that overrides the path set" do
130
- setup do
131
- @output = Whenever.cron \
132
- <<-file
133
- set :job_template, nil
134
- set :path, '/my/path'
135
- every 2.hours do
136
- runner "blahblah", :path => '/some/other/path'
137
- end
138
- file
139
- end
87
+ # runner
140
88
 
141
- should "output the runner using that path" do
142
- assert_match two_hours + %( cd /some/other/path && script/runner -e production 'blahblah'), @output
143
- end
89
+ test "A runner with path set" do
90
+ output = Whenever.cron \
91
+ <<-file
92
+ set :job_template, nil
93
+ set :path, '/my/path'
94
+ every 2.hours do
95
+ runner 'blahblah'
96
+ end
97
+ file
98
+
99
+ assert_match two_hours + %( cd /my/path && script/runner -e production 'blahblah'), output
144
100
  end
145
101
 
146
- context "A runner for an app with bin/rails" do
147
- setup do
148
- Whenever.expects(:path).at_least_once.returns('/my/path')
149
- Whenever.expects(:bin_rails?).returns(true)
150
- @output = Whenever.cron \
151
- <<-file
152
- set :job_template, nil
153
- every 2.hours do
154
- runner 'blahblah'
155
- end
156
- file
157
- end
158
-
159
- should "use a script/rails runner job by default" do
160
- assert_match two_hours + %( cd /my/path && bin/rails runner -e production 'blahblah'), @output
161
- end
102
+ test "A runner that overrides the path set" do
103
+ output = Whenever.cron \
104
+ <<-file
105
+ set :job_template, nil
106
+ set :path, '/my/path'
107
+ every 2.hours do
108
+ runner "blahblah", :path => '/some/other/path'
109
+ end
110
+ file
111
+
112
+ assert_match two_hours + %( cd /some/other/path && script/runner -e production 'blahblah'), output
162
113
  end
163
114
 
164
- context "A runner for an app with script/rails" do
165
- setup do
166
- Whenever.expects(:path).at_least_once.returns('/my/path')
167
- Whenever.expects(:script_rails?).returns(true)
168
- @output = Whenever.cron \
169
- <<-file
170
- set :job_template, nil
171
- every 2.hours do
172
- runner 'blahblah'
173
- end
174
- file
175
- end
115
+ test "A runner for an app with bin/rails" do
116
+ Whenever.expects(:path).at_least_once.returns('/my/path')
117
+ Whenever.expects(:bin_rails?).returns(true)
118
+ output = Whenever.cron \
119
+ <<-file
120
+ set :job_template, nil
121
+ every 2.hours do
122
+ runner 'blahblah'
123
+ end
124
+ file
125
+
126
+ assert_match two_hours + %( cd /my/path && bin/rails runner -e production 'blahblah'), output
127
+ end
176
128
 
177
- should "use a script/rails runner job by default" do
178
- assert_match two_hours + %( cd /my/path && script/rails runner -e production 'blahblah'), @output
179
- end
129
+ test "A runner for an app with script/rails" do
130
+ Whenever.expects(:path).at_least_once.returns('/my/path')
131
+ Whenever.expects(:script_rails?).returns(true)
132
+ output = Whenever.cron \
133
+ <<-file
134
+ set :job_template, nil
135
+ every 2.hours do
136
+ runner 'blahblah'
137
+ end
138
+ file
139
+
140
+ assert_match two_hours + %( cd /my/path && script/rails runner -e production 'blahblah'), output
180
141
  end
181
142
 
182
143
  # rake
183
144
 
184
- context "A rake command with path set" do
185
- setup do
186
- @output = Whenever.cron \
187
- <<-file
188
- set :job_template, nil
189
- set :path, '/my/path'
190
- every 2.hours do
191
- rake "blahblah"
192
- end
193
- file
194
- end
195
-
196
- should "output the rake command using that path" do
197
- assert_match two_hours + ' cd /my/path && RAILS_ENV=production bundle exec rake blahblah --silent', @output
198
- end
145
+ test "A rake command with path set" do
146
+ output = Whenever.cron \
147
+ <<-file
148
+ set :job_template, nil
149
+ set :path, '/my/path'
150
+ every 2.hours do
151
+ rake "blahblah"
152
+ end
153
+ file
154
+
155
+ assert_match two_hours + ' cd /my/path && RAILS_ENV=production bundle exec rake blahblah --silent', output
199
156
  end
200
157
 
201
- context "A rake for a non-bundler app" do
202
- setup do
203
- Whenever.expects(:path).at_least_once.returns('/my/path')
204
- Whenever.expects(:bundler?).returns(false)
205
- @output = Whenever.cron \
206
- <<-file
207
- set :job_template, nil
208
- every 2.hours do
209
- rake 'blahblah'
210
- end
211
- file
212
- end
213
-
214
- should "not use invoke through bundler" do
215
- assert_match two_hours + ' cd /my/path && RAILS_ENV=production rake blahblah --silent', @output
216
- end
158
+ test "A rake for a non-bundler app" do
159
+ Whenever.expects(:path).at_least_once.returns('/my/path')
160
+ Whenever.expects(:bundler?).returns(false)
161
+ output = Whenever.cron \
162
+ <<-file
163
+ set :job_template, nil
164
+ every 2.hours do
165
+ rake 'blahblah'
166
+ end
167
+ file
168
+
169
+ assert_match two_hours + ' cd /my/path && RAILS_ENV=production rake blahblah --silent', output
217
170
  end
218
171
 
219
- context "A rake command that overrides the path set" do
220
- setup do
221
- @output = Whenever.cron \
222
- <<-file
223
- set :job_template, nil
224
- set :path, '/my/path'
225
- every 2.hours do
226
- rake "blahblah", :path => '/some/other/path'
227
- end
228
- file
229
- end
230
-
231
- should "output the rake command using that path" do
232
- assert_match two_hours + ' cd /some/other/path && RAILS_ENV=production bundle exec rake blahblah --silent', @output
233
- end
172
+ test "A rake command that overrides the path set" do
173
+ output = Whenever.cron \
174
+ <<-file
175
+ set :job_template, nil
176
+ set :path, '/my/path'
177
+ every 2.hours do
178
+ rake "blahblah", :path => '/some/other/path'
179
+ end
180
+ file
181
+
182
+ assert_match two_hours + ' cd /some/other/path && RAILS_ENV=production bundle exec rake blahblah --silent', output
234
183
  end
235
184
 
236
- context "A rake command that sets the environment variable" do
237
- setup do
238
- @output = Whenever.cron \
239
- <<-file
240
- set :job_template, nil
241
- set :path, '/my/path'
242
- set :environment_variable, 'RAKE_ENV'
243
- every 2.hours do
244
- rake "blahblah"
245
- end
246
- file
247
- end
248
-
249
- should "output the rake command using that environment variable" do
250
- assert_match two_hours + ' cd /my/path && RAKE_ENV=production bundle exec rake blahblah --silent', @output
251
- end
185
+ test "A rake command that sets the environment variable" do
186
+ output = Whenever.cron \
187
+ <<-file
188
+ set :job_template, nil
189
+ set :path, '/my/path'
190
+ set :environment_variable, 'RAKE_ENV'
191
+ every 2.hours do
192
+ rake "blahblah"
193
+ end
194
+ file
195
+
196
+ assert_match two_hours + ' cd /my/path && RAKE_ENV=production bundle exec rake blahblah --silent', output
252
197
  end
253
198
 
254
- context "A rake command that overrides the environment variable" do
255
- setup do
256
- @output = Whenever.cron \
257
- <<-file
258
- set :job_template, nil
259
- set :path, '/my/path'
260
- set :environment_variable, 'RAKE_ENV'
261
- every 2.hours do
262
- rake "blahblah", :environment_variable => 'SOME_ENV'
263
- end
264
- file
265
- end
266
-
267
- should "output the rake command using that environment variable" do
268
- assert_match two_hours + ' cd /my/path && SOME_ENV=production bundle exec rake blahblah --silent', @output
269
- end
199
+ test "A rake command that overrides the environment variable" do
200
+ output = Whenever.cron \
201
+ <<-file
202
+ set :job_template, nil
203
+ set :path, '/my/path'
204
+ set :environment_variable, 'RAKE_ENV'
205
+ every 2.hours do
206
+ rake "blahblah", :environment_variable => 'SOME_ENV'
207
+ end
208
+ file
209
+
210
+ assert_match two_hours + ' cd /my/path && SOME_ENV=production bundle exec rake blahblah --silent', output
270
211
  end
271
212
 
272
213
  # script
273
214
 
274
- context "A script command with path set" do
275
- setup do
276
- @output = Whenever.cron \
277
- <<-file
278
- set :job_template, nil
279
- set :path, '/my/path'
280
- every 2.hours do
281
- script "blahblah"
282
- end
283
- file
284
- end
285
-
286
- should "output the script command using that path" do
287
- assert_match two_hours + ' cd /my/path && RAILS_ENV=production bundle exec script/blahblah', @output
288
- end
215
+ test "A script command with path set" do
216
+ output = Whenever.cron \
217
+ <<-file
218
+ set :job_template, nil
219
+ set :path, '/my/path'
220
+ every 2.hours do
221
+ script "blahblah"
222
+ end
223
+ file
224
+
225
+ assert_match two_hours + ' cd /my/path && RAILS_ENV=production bundle exec script/blahblah', output
289
226
  end
290
227
 
291
- context "A script command for a non-bundler app" do
292
- setup do
293
- Whenever.expects(:path).at_least_once.returns('/my/path')
294
- Whenever.expects(:bundler?).returns(false)
295
- @output = Whenever.cron \
296
- <<-file
297
- set :job_template, nil
298
- every 2.hours do
299
- script 'blahblah'
300
- end
301
- file
302
- end
303
-
304
- should "not use invoke through bundler" do
305
- assert_match two_hours + ' cd /my/path && RAILS_ENV=production script/blahblah', @output
306
- end
228
+ test "A script command for a non-bundler app" do
229
+ Whenever.expects(:path).at_least_once.returns('/my/path')
230
+ Whenever.expects(:bundler?).returns(false)
231
+ output = Whenever.cron \
232
+ <<-file
233
+ set :job_template, nil
234
+ every 2.hours do
235
+ script 'blahblah'
236
+ end
237
+ file
238
+
239
+ assert_match two_hours + ' cd /my/path && RAILS_ENV=production script/blahblah', output
307
240
  end
308
241
 
309
- context "A script command that uses output" do
310
- setup do
311
- @output = Whenever.cron \
312
- <<-file
313
- set :job_template, nil
314
- set :output, '/log/file'
315
- set :path, '/my/path'
316
- every 2.hours do
317
- script "blahblah", :path => '/some/other/path'
318
- end
319
- file
320
- end
321
-
322
- should "output the script command using that path" do
323
- assert_match two_hours + ' cd /some/other/path && RAILS_ENV=production bundle exec script/blahblah >> /log/file 2>&1', @output
324
- end
242
+ test "A script command that uses output" do
243
+ output = Whenever.cron \
244
+ <<-file
245
+ set :job_template, nil
246
+ set :output, '/log/file'
247
+ set :path, '/my/path'
248
+ every 2.hours do
249
+ script "blahblah", :path => '/some/other/path'
250
+ end
251
+ file
252
+
253
+ assert_match two_hours + ' cd /some/other/path && RAILS_ENV=production bundle exec script/blahblah >> /log/file 2>&1', output
325
254
  end
326
255
 
327
- context "A script command that uses an environment variable" do
328
- setup do
329
- @output = Whenever.cron \
330
- <<-file
331
- set :job_template, nil
332
- set :environment_variable, 'RAKE_ENV'
333
- set :path, '/my/path'
334
- every 2.hours do
335
- script "blahblah"
336
- end
337
- file
338
- end
339
-
340
- should "output the script command using that environment variable" do
341
- assert_match two_hours + ' cd /my/path && RAKE_ENV=production bundle exec script/blahblah', @output
342
- end
256
+ test "A script command that uses an environment variable" do
257
+ output = Whenever.cron \
258
+ <<-file
259
+ set :job_template, nil
260
+ set :environment_variable, 'RAKE_ENV'
261
+ set :path, '/my/path'
262
+ every 2.hours do
263
+ script "blahblah"
264
+ end
265
+ file
266
+
267
+ assert_match two_hours + ' cd /my/path && RAKE_ENV=production bundle exec script/blahblah', output
343
268
  end
344
-
345
269
  end