whenever 0.9.2 → 0.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.travis.yml +17 -7
  4. data/CHANGELOG.md +63 -0
  5. data/Gemfile +0 -5
  6. data/LICENSE +1 -1
  7. data/README.md +101 -18
  8. data/Rakefile +3 -10
  9. data/bin/whenever +3 -0
  10. data/bin/wheneverize +8 -5
  11. data/gemfiles/activesupport4.1.gemfile +5 -0
  12. data/gemfiles/activesupport4.2.gemfile +5 -0
  13. data/lib/whenever/capistrano/v2/recipes.rb +4 -3
  14. data/lib/whenever/capistrano/v3/tasks/whenever.rake +20 -7
  15. data/lib/whenever/capistrano.rb +1 -1
  16. data/lib/whenever/command_line.rb +49 -28
  17. data/lib/whenever/cron.rb +43 -21
  18. data/lib/whenever/job.rb +4 -3
  19. data/lib/whenever/job_list.rb +54 -24
  20. data/lib/whenever/numeric.rb +13 -0
  21. data/lib/whenever/numeric_seconds.rb +48 -0
  22. data/lib/whenever/os.rb +7 -0
  23. data/lib/whenever/setup.rb +5 -1
  24. data/lib/whenever/version.rb +1 -1
  25. data/lib/whenever.rb +15 -14
  26. data/test/functional/command_line_test.rb +379 -255
  27. data/test/functional/output_at_test.rb +227 -249
  28. data/test/functional/output_default_defined_jobs_test.rb +239 -288
  29. data/test/functional/output_defined_job_test.rb +65 -91
  30. data/test/functional/output_env_test.rb +22 -26
  31. data/test/functional/output_jobs_for_roles_test.rb +46 -66
  32. data/test/functional/output_jobs_with_mailto_test.rb +168 -0
  33. data/test/functional/output_redirection_test.rb +231 -309
  34. data/test/test_case.rb +32 -0
  35. data/test/test_helper.rb +44 -15
  36. data/test/unit/capistrano_support_test.rb +126 -148
  37. data/test/unit/cron_test.rb +327 -210
  38. data/test/unit/executable_test.rb +142 -0
  39. data/test/unit/job_test.rb +111 -121
  40. data/whenever.gemspec +5 -4
  41. metadata +37 -28
  42. data/lib/whenever/tasks/whenever.rake +0 -43
@@ -1,345 +1,296 @@
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 && bundle exec 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
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 && bundle exec script/runner -e production 'blahblah'), output
113
+ end
158
114
 
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
115
+ test "A runner for a non-bundler app" do
116
+ Whenever.expects(:bundler?).returns(false)
117
+ output = Whenever.cron \
118
+ <<-file
119
+ set :job_template, nil
120
+ set :path, '/my/path'
121
+ every 2.hours do
122
+ runner 'blahblah'
123
+ end
124
+ file
125
+
126
+ assert_match two_hours + %( cd /my/path && script/runner -e production 'blahblah'), output
162
127
  end
163
128
 
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
129
+ test "A runner for an app with bin/rails" do
130
+ Whenever.expects(:path).at_least_once.returns('/my/path')
131
+ Whenever.expects(:bin_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 && bin/rails runner -e production 'blahblah'), output
141
+ end
176
142
 
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
143
+ test "A runner for an app with script/rails" do
144
+ Whenever.expects(:path).at_least_once.returns('/my/path')
145
+ Whenever.expects(:script_rails?).returns(true)
146
+ output = Whenever.cron \
147
+ <<-file
148
+ set :job_template, nil
149
+ every 2.hours do
150
+ runner 'blahblah'
151
+ end
152
+ file
153
+
154
+ assert_match two_hours + %( cd /my/path && script/rails runner -e production 'blahblah'), output
180
155
  end
181
156
 
182
157
  # rake
183
158
 
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
159
+ test "A rake command with path set" do
160
+ output = Whenever.cron \
161
+ <<-file
162
+ set :job_template, nil
163
+ set :path, '/my/path'
164
+ every 2.hours do
165
+ rake "blahblah"
166
+ end
167
+ file
168
+
169
+ assert_match two_hours + ' cd /my/path && RAILS_ENV=production bundle exec rake blahblah --silent', output
199
170
  end
200
171
 
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
172
+ test "A rake command with arguments" 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[foobar]"
179
+ end
180
+ file
181
+
182
+ assert_match two_hours + ' cd /my/path && RAILS_ENV=production bundle exec rake blahblah[foobar] --silent', output
217
183
  end
218
184
 
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
185
+ test "A rake for a non-bundler app" do
186
+ Whenever.expects(:path).at_least_once.returns('/my/path')
187
+ Whenever.expects(:bundler?).returns(false)
188
+ output = Whenever.cron \
189
+ <<-file
190
+ set :job_template, nil
191
+ every 2.hours do
192
+ rake 'blahblah'
193
+ end
194
+ file
195
+
196
+ assert_match two_hours + ' cd /my/path && RAILS_ENV=production rake blahblah --silent', output
234
197
  end
235
198
 
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
199
+ test "A rake command that overrides the path set" do
200
+ output = Whenever.cron \
201
+ <<-file
202
+ set :job_template, nil
203
+ set :path, '/my/path'
204
+ every 2.hours do
205
+ rake "blahblah", :path => '/some/other/path'
206
+ end
207
+ file
208
+
209
+ assert_match two_hours + ' cd /some/other/path && RAILS_ENV=production bundle exec rake blahblah --silent', output
252
210
  end
253
211
 
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
212
+ test "A rake command that sets the environment variable" do
213
+ output = Whenever.cron \
214
+ <<-file
215
+ set :job_template, nil
216
+ set :path, '/my/path'
217
+ set :environment_variable, 'RAKE_ENV'
218
+ every 2.hours do
219
+ rake "blahblah"
220
+ end
221
+ file
222
+
223
+ assert_match two_hours + ' cd /my/path && RAKE_ENV=production bundle exec rake blahblah --silent', output
224
+ end
266
225
 
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
226
+ test "A rake command that overrides the environment variable" do
227
+ output = Whenever.cron \
228
+ <<-file
229
+ set :job_template, nil
230
+ set :path, '/my/path'
231
+ set :environment_variable, 'RAKE_ENV'
232
+ every 2.hours do
233
+ rake "blahblah", :environment_variable => 'SOME_ENV'
234
+ end
235
+ file
236
+
237
+ assert_match two_hours + ' cd /my/path && SOME_ENV=production bundle exec rake blahblah --silent', output
270
238
  end
271
239
 
272
240
  # script
273
241
 
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
242
+ test "A script command with path set" do
243
+ output = Whenever.cron \
244
+ <<-file
245
+ set :job_template, nil
246
+ set :path, '/my/path'
247
+ every 2.hours do
248
+ script "blahblah"
249
+ end
250
+ file
251
+
252
+ assert_match two_hours + ' cd /my/path && RAILS_ENV=production bundle exec script/blahblah', output
289
253
  end
290
254
 
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
255
+ test "A script command for a non-bundler app" do
256
+ Whenever.expects(:path).at_least_once.returns('/my/path')
257
+ Whenever.expects(:bundler?).returns(false)
258
+ output = Whenever.cron \
259
+ <<-file
260
+ set :job_template, nil
261
+ every 2.hours do
262
+ script 'blahblah'
263
+ end
264
+ file
265
+
266
+ assert_match two_hours + ' cd /my/path && RAILS_ENV=production script/blahblah', output
307
267
  end
308
268
 
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
269
+ test "A script command that uses output" do
270
+ output = Whenever.cron \
271
+ <<-file
272
+ set :job_template, nil
273
+ set :output, '/log/file'
274
+ set :path, '/my/path'
275
+ every 2.hours do
276
+ script "blahblah", :path => '/some/other/path'
277
+ end
278
+ file
279
+
280
+ assert_match two_hours + ' cd /some/other/path && RAILS_ENV=production bundle exec script/blahblah >> /log/file 2>&1', output
325
281
  end
326
282
 
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
283
+ test "A script command that uses an environment variable" do
284
+ output = Whenever.cron \
285
+ <<-file
286
+ set :job_template, nil
287
+ set :environment_variable, 'RAKE_ENV'
288
+ set :path, '/my/path'
289
+ every 2.hours do
290
+ script "blahblah"
291
+ end
292
+ file
293
+
294
+ assert_match two_hours + ' cd /my/path && RAKE_ENV=production bundle exec script/blahblah', output
343
295
  end
344
-
345
296
  end