whenever 0.5.0 → 0.6.1
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/.gitignore +2 -1
- data/CHANGELOG.rdoc +27 -0
- data/README.rdoc +40 -28
- data/Rakefile +11 -8
- data/bin/whenever +11 -5
- data/lib/whenever/capistrano.rb +31 -0
- data/lib/whenever/command_line.rb +20 -6
- data/lib/whenever/{outputs/cron.rb → cron.rb} +4 -11
- data/lib/whenever/job.rb +32 -7
- data/lib/whenever/job_list.rb +9 -19
- data/lib/whenever/job_types/default.rb +11 -3
- data/lib/whenever/output_redirection.rb +58 -0
- data/lib/whenever/version.rb +1 -1
- data/lib/whenever.rb +3 -13
- data/test/{command_line_test.rb → functional/command_line_test.rb} +156 -3
- data/test/{output_at_test.rb → functional/output_at_test.rb} +20 -6
- data/test/functional/output_default_defined_jobs_test.rb +145 -0
- data/test/{output_defined_job_test.rb → functional/output_defined_job_test.rb} +25 -1
- data/test/functional/output_env_test.rb +23 -0
- data/test/{output_redirection_test.rb → functional/output_redirection_test.rb} +19 -1
- data/test/test_helper.rb +5 -18
- data/test/{cron_test.rb → unit/cron_test.rb} +1 -1
- data/test/unit/job_test.rb +77 -0
- data/whenever.gemspec +38 -30
- metadata +77 -30
- data/lib/whenever/outputs/cron/output_redirection.rb +0 -60
- data/test/output_command_test.rb +0 -37
- data/test/output_env_test.rb +0 -56
- data/test/output_rake_test.rb +0 -74
- data/test/output_runner_test.rb +0 -175
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + "
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + "/../test_helper")
|
|
2
2
|
|
|
3
3
|
class CommandLineTest < Test::Unit::TestCase
|
|
4
4
|
|
|
@@ -65,8 +65,6 @@ This shouldn't get replaced
|
|
|
65
65
|
# End Whenever generated tasks for: Other identifier
|
|
66
66
|
EXISTING_CRON
|
|
67
67
|
|
|
68
|
-
@command.expects(:read_crontab).at_least_once.returns(existing)
|
|
69
|
-
|
|
70
68
|
new_cron = <<-NEW_CRON
|
|
71
69
|
# Something
|
|
72
70
|
|
|
@@ -79,12 +77,52 @@ This shouldn't get replaced
|
|
|
79
77
|
# End Whenever generated tasks for: Other identifier
|
|
80
78
|
NEW_CRON
|
|
81
79
|
|
|
80
|
+
@command.expects(:read_crontab).at_least_once.returns(existing)
|
|
82
81
|
assert_equal new_cron, @command.send(:updated_crontab)
|
|
83
82
|
|
|
84
83
|
@command.expects(:write_crontab).with(new_cron).returns(true)
|
|
85
84
|
assert @command.run
|
|
86
85
|
end
|
|
87
86
|
end
|
|
87
|
+
|
|
88
|
+
context "A command line update that contains backslashes" do
|
|
89
|
+
setup do
|
|
90
|
+
@existing = <<-EXISTING_CRON
|
|
91
|
+
# Begin Whenever generated tasks for: My identifier
|
|
92
|
+
script/runner -e production 'puts '\\''hello'\\'''
|
|
93
|
+
# End Whenever generated tasks for: My identifier
|
|
94
|
+
EXISTING_CRON
|
|
95
|
+
File.expects(:exists?).with('config/schedule.rb').returns(true)
|
|
96
|
+
@command = Whenever::CommandLine.new(:update => true, :identifier => 'My identifier')
|
|
97
|
+
@command.expects(:read_crontab).at_least_once.returns(@existing)
|
|
98
|
+
@command.expects(:whenever_cron).returns(@existing)
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
should "replace the existing block with the backslashes in tact" do
|
|
102
|
+
assert_equal @existing, @command.send(:updated_crontab)
|
|
103
|
+
end
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
context "A command line update with an identifier similar to an existing one in the crontab already" do
|
|
107
|
+
setup do
|
|
108
|
+
@existing = <<-EXISTING_CRON
|
|
109
|
+
# Begin Whenever generated tasks for: WheneverExisting
|
|
110
|
+
# End Whenever generated tasks for: WheneverExisting
|
|
111
|
+
EXISTING_CRON
|
|
112
|
+
@new = <<-NEW_CRON
|
|
113
|
+
# Begin Whenever generated tasks for: Whenever
|
|
114
|
+
# End Whenever generated tasks for: Whenever
|
|
115
|
+
NEW_CRON
|
|
116
|
+
File.expects(:exists?).with('config/schedule.rb').returns(true)
|
|
117
|
+
@command = Whenever::CommandLine.new(:update => true, :identifier => 'Whenever')
|
|
118
|
+
@command.expects(:read_crontab).at_least_once.returns(@existing)
|
|
119
|
+
@command.expects(:whenever_cron).returns(@new)
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
should "append the similarly named command" do
|
|
123
|
+
assert_equal @existing + "\n\n" + @new, @command.send(:updated_crontab)
|
|
124
|
+
end
|
|
125
|
+
end
|
|
88
126
|
|
|
89
127
|
context "A command line delete" do
|
|
90
128
|
setup do
|
|
@@ -174,4 +212,119 @@ NEW_CRON
|
|
|
174
212
|
@command = Whenever::CommandLine.new(:update => true, :clear => true)
|
|
175
213
|
end
|
|
176
214
|
end
|
|
215
|
+
|
|
216
|
+
context "A runner where the environment is overridden using the :set option" do
|
|
217
|
+
setup do
|
|
218
|
+
@output = Whenever.cron :set => 'environment=serious', :string => \
|
|
219
|
+
<<-file
|
|
220
|
+
set :job_template, nil
|
|
221
|
+
set :environment, :silly
|
|
222
|
+
set :path, '/my/path'
|
|
223
|
+
every 2.hours do
|
|
224
|
+
runner "blahblah"
|
|
225
|
+
end
|
|
226
|
+
file
|
|
227
|
+
end
|
|
228
|
+
|
|
229
|
+
should "output the runner using the override environment" do
|
|
230
|
+
assert_match two_hours + %( cd /my/path && script/runner -e serious 'blahblah'), @output
|
|
231
|
+
end
|
|
232
|
+
end
|
|
233
|
+
|
|
234
|
+
context "A runner where the environment and path are overridden using the :set option" do
|
|
235
|
+
setup do
|
|
236
|
+
@output = Whenever.cron :set => 'environment=serious&path=/serious/path', :string => \
|
|
237
|
+
<<-file
|
|
238
|
+
set :job_template, nil
|
|
239
|
+
set :environment, :silly
|
|
240
|
+
set :path, '/silly/path'
|
|
241
|
+
every 2.hours do
|
|
242
|
+
runner "blahblah"
|
|
243
|
+
end
|
|
244
|
+
file
|
|
245
|
+
end
|
|
246
|
+
|
|
247
|
+
should "output the runner using the overridden path and environment" do
|
|
248
|
+
assert_match two_hours + %( cd /serious/path && script/runner -e serious 'blahblah'), @output
|
|
249
|
+
end
|
|
250
|
+
end
|
|
251
|
+
|
|
252
|
+
context "A runner where the environment and path are overridden using the :set option with spaces in the string" do
|
|
253
|
+
setup do
|
|
254
|
+
@output = Whenever.cron :set => ' environment = serious& path =/serious/path', :string => \
|
|
255
|
+
<<-file
|
|
256
|
+
set :job_template, nil
|
|
257
|
+
set :environment, :silly
|
|
258
|
+
set :path, '/silly/path'
|
|
259
|
+
every 2.hours do
|
|
260
|
+
runner "blahblah"
|
|
261
|
+
end
|
|
262
|
+
file
|
|
263
|
+
end
|
|
264
|
+
|
|
265
|
+
should "output the runner using the overridden path and environment" do
|
|
266
|
+
assert_match two_hours + %( cd /serious/path && script/runner -e serious 'blahblah'), @output
|
|
267
|
+
end
|
|
268
|
+
end
|
|
269
|
+
|
|
270
|
+
context "A runner where the environment is overridden using the :set option but no value is given" do
|
|
271
|
+
setup do
|
|
272
|
+
@output = Whenever.cron :set => ' environment=', :string => \
|
|
273
|
+
<<-file
|
|
274
|
+
set :job_template, nil
|
|
275
|
+
set :environment, :silly
|
|
276
|
+
set :path, '/silly/path'
|
|
277
|
+
every 2.hours do
|
|
278
|
+
runner "blahblah"
|
|
279
|
+
end
|
|
280
|
+
file
|
|
281
|
+
end
|
|
282
|
+
|
|
283
|
+
should "output the runner using the original environmnet" do
|
|
284
|
+
assert_match two_hours + %( cd /silly/path && script/runner -e silly 'blahblah'), @output
|
|
285
|
+
end
|
|
286
|
+
end
|
|
287
|
+
|
|
288
|
+
context "prepare-ing the output" do
|
|
289
|
+
setup do
|
|
290
|
+
File.expects(:exists?).with('config/schedule.rb').returns(true)
|
|
291
|
+
end
|
|
292
|
+
|
|
293
|
+
should "not trim off the top lines of the file" do
|
|
294
|
+
@command = Whenever::CommandLine.new(:update => true, :identifier => 'My identifier', :cut => 0)
|
|
295
|
+
existing = <<-EXISTING_CRON
|
|
296
|
+
# Useless Comments
|
|
297
|
+
# at the top of the file
|
|
298
|
+
|
|
299
|
+
# Begin Whenever generated tasks for: My identifier
|
|
300
|
+
My whenever job that was already here
|
|
301
|
+
# End Whenever generated tasks for: My identifier
|
|
302
|
+
EXISTING_CRON
|
|
303
|
+
|
|
304
|
+
# here-doc adds an extra newline we need removed
|
|
305
|
+
assert_equal existing.strip, @command.send(:prepare, existing)
|
|
306
|
+
end
|
|
307
|
+
|
|
308
|
+
should "trim off the top lines of the file" do
|
|
309
|
+
@command = Whenever::CommandLine.new(:update => true, :identifier => 'My identifier', :cut => '3')
|
|
310
|
+
existing = <<-EXISTING_CRON
|
|
311
|
+
# Useless Comments
|
|
312
|
+
# at the top of the file
|
|
313
|
+
|
|
314
|
+
# Begin Whenever generated tasks for: My identifier
|
|
315
|
+
My whenever job that was already here
|
|
316
|
+
# End Whenever generated tasks for: My identifier
|
|
317
|
+
EXISTING_CRON
|
|
318
|
+
|
|
319
|
+
new_cron = <<-NEW_CRON
|
|
320
|
+
# Begin Whenever generated tasks for: My identifier
|
|
321
|
+
My whenever job that was already here
|
|
322
|
+
# End Whenever generated tasks for: My identifier
|
|
323
|
+
NEW_CRON
|
|
324
|
+
|
|
325
|
+
# here-doc adds an extra newline we need removed
|
|
326
|
+
assert_equal new_cron.strip, @command.send(:prepare, existing)
|
|
327
|
+
end
|
|
328
|
+
end
|
|
329
|
+
|
|
177
330
|
end
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + "
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + "/../test_helper")
|
|
2
2
|
|
|
3
3
|
class OutputAtTest < Test::Unit::TestCase
|
|
4
4
|
|
|
@@ -6,6 +6,7 @@ class OutputAtTest < Test::Unit::TestCase
|
|
|
6
6
|
setup do
|
|
7
7
|
@output = Whenever.cron \
|
|
8
8
|
<<-file
|
|
9
|
+
set :job_template, nil
|
|
9
10
|
every "weekday", :at => '5:02am' do
|
|
10
11
|
command "blahblah"
|
|
11
12
|
end
|
|
@@ -21,6 +22,7 @@ class OutputAtTest < Test::Unit::TestCase
|
|
|
21
22
|
setup do
|
|
22
23
|
@output = Whenever.cron \
|
|
23
24
|
<<-file
|
|
25
|
+
set :job_template, nil
|
|
24
26
|
every "weekday", :at => %w(5:02am 3:52pm) do
|
|
25
27
|
command "blahblah"
|
|
26
28
|
end
|
|
@@ -37,6 +39,7 @@ class OutputAtTest < Test::Unit::TestCase
|
|
|
37
39
|
setup do
|
|
38
40
|
@output = Whenever.cron \
|
|
39
41
|
<<-file
|
|
42
|
+
set :job_template, nil
|
|
40
43
|
every "weekday", :at => '5:02am, 3:52pm' do
|
|
41
44
|
command "blahblah"
|
|
42
45
|
end
|
|
@@ -53,6 +56,7 @@ class OutputAtTest < Test::Unit::TestCase
|
|
|
53
56
|
setup do
|
|
54
57
|
@output = Whenever.cron \
|
|
55
58
|
<<-file
|
|
59
|
+
set :job_template, nil
|
|
56
60
|
every "weekday", :at => '5:02am, 3:02pm' do
|
|
57
61
|
command "blahblah"
|
|
58
62
|
end
|
|
@@ -68,6 +72,7 @@ class OutputAtTest < Test::Unit::TestCase
|
|
|
68
72
|
setup do
|
|
69
73
|
@output = Whenever.cron \
|
|
70
74
|
<<-file
|
|
75
|
+
set :job_template, nil
|
|
71
76
|
every "mon,wed,fri", :at => '5:02am, 3:02pm' do
|
|
72
77
|
command "blahblah"
|
|
73
78
|
end
|
|
@@ -83,6 +88,7 @@ class OutputAtTest < Test::Unit::TestCase
|
|
|
83
88
|
setup do
|
|
84
89
|
@output = Whenever.cron \
|
|
85
90
|
<<-file
|
|
91
|
+
set :job_template, nil
|
|
86
92
|
set :path, '/your/path'
|
|
87
93
|
every "mon,wed,fri", :at => '5:02am, 3:02pm' do
|
|
88
94
|
runner "blahblah"
|
|
@@ -91,7 +97,7 @@ class OutputAtTest < Test::Unit::TestCase
|
|
|
91
97
|
end
|
|
92
98
|
|
|
93
99
|
should "output the runner using one entry because the times are aligned" do
|
|
94
|
-
assert_match
|
|
100
|
+
assert_match %(2 5,15 * * 1,3,5 cd /your/path && script/runner -e production 'blahblah'), @output
|
|
95
101
|
end
|
|
96
102
|
end
|
|
97
103
|
|
|
@@ -99,6 +105,7 @@ class OutputAtTest < Test::Unit::TestCase
|
|
|
99
105
|
setup do
|
|
100
106
|
@output = Whenever.cron \
|
|
101
107
|
<<-file
|
|
108
|
+
set :job_template, nil
|
|
102
109
|
set :path, '/your/path'
|
|
103
110
|
every "mon,wed,fri", :at => '5:02am, 3:02pm' do
|
|
104
111
|
rake "blah:blah"
|
|
@@ -107,7 +114,7 @@ class OutputAtTest < Test::Unit::TestCase
|
|
|
107
114
|
end
|
|
108
115
|
|
|
109
116
|
should "output the rake task using one entry because the times are aligned" do
|
|
110
|
-
assert_match '2 5,15 * * 1,3,5 cd /your/path && RAILS_ENV=production
|
|
117
|
+
assert_match '2 5,15 * * 1,3,5 cd /your/path && RAILS_ENV=production rake blah:blah --silent', @output
|
|
111
118
|
end
|
|
112
119
|
end
|
|
113
120
|
|
|
@@ -115,6 +122,7 @@ class OutputAtTest < Test::Unit::TestCase
|
|
|
115
122
|
setup do
|
|
116
123
|
@output = Whenever.cron \
|
|
117
124
|
<<-file
|
|
125
|
+
set :job_template, nil
|
|
118
126
|
every [1.month, 1.day], :at => 'january 5:02am, june 17th at 2:22pm, june 3rd at 3:33am' do
|
|
119
127
|
command "blahblah"
|
|
120
128
|
end
|
|
@@ -138,6 +146,7 @@ class OutputAtTest < Test::Unit::TestCase
|
|
|
138
146
|
setup do
|
|
139
147
|
@output = Whenever.cron \
|
|
140
148
|
<<-file
|
|
149
|
+
set :job_template, nil
|
|
141
150
|
every :reboot do
|
|
142
151
|
command "command_1"
|
|
143
152
|
command "command_2"
|
|
@@ -155,6 +164,7 @@ class OutputAtTest < Test::Unit::TestCase
|
|
|
155
164
|
setup do
|
|
156
165
|
@output = Whenever.cron \
|
|
157
166
|
<<-file
|
|
167
|
+
set :job_template, nil
|
|
158
168
|
set :path, '/your/path'
|
|
159
169
|
every :day do
|
|
160
170
|
rake "blah:blah"
|
|
@@ -167,10 +177,10 @@ class OutputAtTest < Test::Unit::TestCase
|
|
|
167
177
|
end
|
|
168
178
|
|
|
169
179
|
should "output all of the commands @daily" do
|
|
170
|
-
assert_match '@daily cd /your/path && RAILS_ENV=production
|
|
171
|
-
assert_match
|
|
180
|
+
assert_match '@daily cd /your/path && RAILS_ENV=production rake blah:blah --silent', @output
|
|
181
|
+
assert_match %(@daily cd /your/path && script/runner -e production 'runner_1'), @output
|
|
172
182
|
assert_match '@daily command_1', @output
|
|
173
|
-
assert_match
|
|
183
|
+
assert_match %(@daily cd /your/path && script/runner -e production 'runner_2'), @output
|
|
174
184
|
assert_match '@daily command_2', @output
|
|
175
185
|
end
|
|
176
186
|
end
|
|
@@ -179,6 +189,7 @@ class OutputAtTest < Test::Unit::TestCase
|
|
|
179
189
|
setup do
|
|
180
190
|
@output = Whenever.cron \
|
|
181
191
|
<<-file
|
|
192
|
+
set :job_template, nil
|
|
182
193
|
every 5.minutes, :at => 1 do
|
|
183
194
|
command "blahblah"
|
|
184
195
|
end
|
|
@@ -194,6 +205,7 @@ class OutputAtTest < Test::Unit::TestCase
|
|
|
194
205
|
setup do
|
|
195
206
|
@output = Whenever.cron \
|
|
196
207
|
<<-file
|
|
208
|
+
set :job_template, nil
|
|
197
209
|
every 4.minutes, :at => 2 do
|
|
198
210
|
command "blahblah"
|
|
199
211
|
end
|
|
@@ -209,6 +221,7 @@ class OutputAtTest < Test::Unit::TestCase
|
|
|
209
221
|
setup do
|
|
210
222
|
@output = Whenever.cron \
|
|
211
223
|
<<-file
|
|
224
|
+
set :job_template, nil
|
|
212
225
|
every 3.minutes, :at => 7 do
|
|
213
226
|
command "blahblah"
|
|
214
227
|
end
|
|
@@ -224,6 +237,7 @@ class OutputAtTest < Test::Unit::TestCase
|
|
|
224
237
|
setup do
|
|
225
238
|
@output = Whenever.cron \
|
|
226
239
|
<<-file
|
|
240
|
+
set :job_template, nil
|
|
227
241
|
every 2.minutes, :at => 27 do
|
|
228
242
|
command "blahblah"
|
|
229
243
|
end
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + "/../test_helper")
|
|
2
|
+
|
|
3
|
+
class OutputDefaultDefinedJobsTest < Test::Unit::TestCase
|
|
4
|
+
|
|
5
|
+
# command
|
|
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
|
|
17
|
+
|
|
18
|
+
should "output the command" do
|
|
19
|
+
assert_match /^.+ .+ .+ .+ blahblah$/, @output
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
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
|
|
32
|
+
|
|
33
|
+
should "output the command with the default job template" do
|
|
34
|
+
assert_match /^.+ .+ .+ .+ \/bin\/bash -l -c 'blahblah'$/, @output
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
context "A plain command that overrides the job_template set" do
|
|
39
|
+
setup do
|
|
40
|
+
@output = Whenever.cron \
|
|
41
|
+
<<-file
|
|
42
|
+
set :job_template, "/bin/bash -l -c ':job'"
|
|
43
|
+
every 2.hours do
|
|
44
|
+
command "blahblah", :job_template => "/bin/sh -l -c ':job'"
|
|
45
|
+
end
|
|
46
|
+
file
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
should "output the command using that job_template" do
|
|
50
|
+
assert_match /^.+ .+ .+ .+ \/bin\/sh -l -c 'blahblah'$/, @output
|
|
51
|
+
assert_no_match /bash/, @output
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
# runner
|
|
56
|
+
|
|
57
|
+
context "A runner with path set" do
|
|
58
|
+
setup do
|
|
59
|
+
@output = Whenever.cron \
|
|
60
|
+
<<-file
|
|
61
|
+
set :job_template, nil
|
|
62
|
+
set :path, '/my/path'
|
|
63
|
+
every 2.hours do
|
|
64
|
+
runner 'blahblah'
|
|
65
|
+
end
|
|
66
|
+
file
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
should "output the runner using that path" do
|
|
70
|
+
assert_match two_hours + %( cd /my/path && script/runner -e production 'blahblah'), @output
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
context "A runner that overrides the path set" do
|
|
75
|
+
setup do
|
|
76
|
+
@output = Whenever.cron \
|
|
77
|
+
<<-file
|
|
78
|
+
set :job_template, nil
|
|
79
|
+
set :path, '/my/path'
|
|
80
|
+
every 2.hours do
|
|
81
|
+
runner "blahblah", :path => '/some/other/path'
|
|
82
|
+
end
|
|
83
|
+
file
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
should "output the runner using that path" do
|
|
87
|
+
assert_match two_hours + %( cd /some/other/path && script/runner -e production 'blahblah'), @output
|
|
88
|
+
end
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
context "A runner for a Rails 3 app" do
|
|
92
|
+
setup do
|
|
93
|
+
Whenever.expects(:path).at_least_once.returns('/my/path')
|
|
94
|
+
File.expects(:exists?).with('/my/path/script/rails').returns(true)
|
|
95
|
+
@output = Whenever.cron \
|
|
96
|
+
<<-file
|
|
97
|
+
set :job_template, nil
|
|
98
|
+
every 2.hours do
|
|
99
|
+
runner 'blahblah'
|
|
100
|
+
end
|
|
101
|
+
file
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
should "use the Rails 3 runner job by default" do
|
|
105
|
+
assert_match two_hours + %( cd /my/path && script/rails runner -e production 'blahblah'), @output
|
|
106
|
+
end
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
# rake
|
|
110
|
+
|
|
111
|
+
context "A rake command with path set" do
|
|
112
|
+
setup do
|
|
113
|
+
@output = Whenever.cron \
|
|
114
|
+
<<-file
|
|
115
|
+
set :job_template, nil
|
|
116
|
+
set :path, '/my/path'
|
|
117
|
+
every 2.hours do
|
|
118
|
+
rake "blahblah"
|
|
119
|
+
end
|
|
120
|
+
file
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
should "output the rake command using that path" do
|
|
124
|
+
assert_match two_hours + ' cd /my/path && RAILS_ENV=production rake blahblah --silent', @output
|
|
125
|
+
end
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
context "A rake command that overrides the path set" do
|
|
129
|
+
setup do
|
|
130
|
+
@output = Whenever.cron \
|
|
131
|
+
<<-file
|
|
132
|
+
set :job_template, nil
|
|
133
|
+
set :path, '/my/path'
|
|
134
|
+
every 2.hours do
|
|
135
|
+
rake "blahblah", :path => '/some/other/path'
|
|
136
|
+
end
|
|
137
|
+
file
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
should "output the rake command using that path" do
|
|
141
|
+
assert_match two_hours + ' cd /some/other/path && RAILS_ENV=production rake blahblah --silent', @output
|
|
142
|
+
end
|
|
143
|
+
end
|
|
144
|
+
|
|
145
|
+
end
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + "
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + "/../test_helper")
|
|
2
2
|
|
|
3
3
|
class OutputDefinedJobTest < Test::Unit::TestCase
|
|
4
4
|
|
|
@@ -6,6 +6,7 @@ class OutputDefinedJobTest < Test::Unit::TestCase
|
|
|
6
6
|
setup do
|
|
7
7
|
@output = Whenever.cron \
|
|
8
8
|
<<-file
|
|
9
|
+
set :job_template, nil
|
|
9
10
|
job_type :some_job, "before :task after"
|
|
10
11
|
every 2.hours do
|
|
11
12
|
some_job "during"
|
|
@@ -22,6 +23,7 @@ class OutputDefinedJobTest < Test::Unit::TestCase
|
|
|
22
23
|
setup do
|
|
23
24
|
@output = Whenever.cron \
|
|
24
25
|
<<-file
|
|
26
|
+
set :job_template, nil
|
|
25
27
|
job_type :some_job, "before :task after :option1 :option2"
|
|
26
28
|
every 2.hours do
|
|
27
29
|
some_job "during", :option1 => 'happy', :option2 => 'birthday'
|
|
@@ -38,6 +40,7 @@ class OutputDefinedJobTest < Test::Unit::TestCase
|
|
|
38
40
|
setup do
|
|
39
41
|
@output = Whenever.cron \
|
|
40
42
|
<<-file
|
|
43
|
+
set :job_template, nil
|
|
41
44
|
job_type :some_job, "before :task after :option1"
|
|
42
45
|
set :option1, 'happy'
|
|
43
46
|
every 2.hours do
|
|
@@ -55,6 +58,7 @@ class OutputDefinedJobTest < Test::Unit::TestCase
|
|
|
55
58
|
setup do
|
|
56
59
|
@output = Whenever.cron \
|
|
57
60
|
<<-file
|
|
61
|
+
set :job_template, nil
|
|
58
62
|
job_type :some_job, "before :task after :option1"
|
|
59
63
|
set :option1, 'global'
|
|
60
64
|
every 2.hours do
|
|
@@ -72,6 +76,7 @@ class OutputDefinedJobTest < Test::Unit::TestCase
|
|
|
72
76
|
setup do
|
|
73
77
|
@output = Whenever.cron \
|
|
74
78
|
<<-file
|
|
79
|
+
set :job_template, nil
|
|
75
80
|
job_type :some_job, "before :task after :option1"
|
|
76
81
|
every 2.hours do
|
|
77
82
|
some_job "during", :option2 => 'happy'
|
|
@@ -84,4 +89,23 @@ class OutputDefinedJobTest < Test::Unit::TestCase
|
|
|
84
89
|
end
|
|
85
90
|
end
|
|
86
91
|
|
|
92
|
+
context "A defined job that uses a :path where none is explicitly set" do
|
|
93
|
+
setup do
|
|
94
|
+
Whenever.stubs(:path).returns('/my/path')
|
|
95
|
+
|
|
96
|
+
@output = Whenever.cron \
|
|
97
|
+
<<-file
|
|
98
|
+
set :job_template, nil
|
|
99
|
+
job_type :some_job, "cd :path && :task"
|
|
100
|
+
every 2.hours do
|
|
101
|
+
some_job 'blahblah'
|
|
102
|
+
end
|
|
103
|
+
file
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
should "default to using the Whenever.path" do
|
|
107
|
+
assert_match two_hours + %( cd /my/path && blahblah), @output
|
|
108
|
+
end
|
|
109
|
+
end
|
|
110
|
+
|
|
87
111
|
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + "/../test_helper")
|
|
2
|
+
|
|
3
|
+
class OutputEnvTest < Test::Unit::TestCase
|
|
4
|
+
|
|
5
|
+
context "The output from Whenever with environment variables set" do
|
|
6
|
+
setup do
|
|
7
|
+
@output = Whenever.cron \
|
|
8
|
+
<<-file
|
|
9
|
+
env :MYVAR, 'blah'
|
|
10
|
+
env 'MAILTO', "someone@example.com"
|
|
11
|
+
file
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
should "output MYVAR environment variable" do
|
|
15
|
+
assert_match "MYVAR=blah", @output
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
should "output MAILTO environment variable" do
|
|
19
|
+
assert_match "MAILTO=someone@example.com", @output
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
end
|