whenever 0.4.1 → 0.5.2
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 +31 -0
- data/README.rdoc +24 -12
- data/Rakefile +9 -6
- data/bin/whenever +8 -3
- data/lib/whenever/base.rb +1 -5
- data/lib/whenever/command_line.rb +22 -6
- data/lib/whenever/{outputs/cron.rb → cron.rb} +3 -5
- data/lib/whenever/job.rb +41 -0
- data/lib/whenever/job_list.rb +24 -24
- data/lib/whenever/job_types/default.rb +3 -27
- data/lib/whenever/{outputs/cron/output_redirection.rb → output_redirection.rb} +9 -3
- data/lib/whenever/version.rb +1 -1
- data/lib/whenever.rb +4 -25
- data/test/functional/command_line_test.rb +288 -0
- data/test/{output_at_test.rb → functional/output_at_test.rb} +63 -4
- data/test/{output_rake_test.rb → functional/output_default_defined_jobs_test.rb} +37 -21
- data/test/functional/output_defined_job_test.rb +105 -0
- data/test/{output_env_test.rb → functional/output_env_test.rb} +1 -1
- data/test/{output_redirection_test.rb → functional/output_redirection_test.rb} +11 -11
- data/test/test_helper.rb +5 -18
- data/test/{cron_test.rb → unit/cron_test.rb} +1 -1
- data/test/unit/job_test.rb +69 -0
- data/whenever.gemspec +35 -27
- metadata +82 -30
- data/lib/whenever/job_types/rake_task.rb +0 -12
- data/lib/whenever/job_types/runner.rb +0 -12
- data/test/command_line_test.rb +0 -101
- data/test/output_command_test.rb +0 -37
- data/test/output_runner_test.rb +0 -209
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + "/../test_helper")
|
|
2
|
+
|
|
3
|
+
class CommandLineTest < Test::Unit::TestCase
|
|
4
|
+
|
|
5
|
+
context "A command line write" do
|
|
6
|
+
setup do
|
|
7
|
+
File.expects(:exists?).with('config/schedule.rb').returns(true)
|
|
8
|
+
@command = Whenever::CommandLine.new(:write => true, :identifier => 'My identifier')
|
|
9
|
+
@task = "#{two_hours} /my/command"
|
|
10
|
+
Whenever.expects(:cron).returns(@task)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
should "output the cron job with identifier blocks" do
|
|
14
|
+
output = <<-EXPECTED
|
|
15
|
+
# Begin Whenever generated tasks for: My identifier
|
|
16
|
+
#{@task}
|
|
17
|
+
# End Whenever generated tasks for: My identifier
|
|
18
|
+
EXPECTED
|
|
19
|
+
|
|
20
|
+
assert_equal output, @command.send(:whenever_cron)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
should "write the crontab when run" do
|
|
24
|
+
@command.expects(:write_crontab).returns(true)
|
|
25
|
+
assert @command.run
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
context "A command line update" do
|
|
30
|
+
setup do
|
|
31
|
+
File.expects(:exists?).with('config/schedule.rb').returns(true)
|
|
32
|
+
@command = Whenever::CommandLine.new(:update => true, :identifier => 'My identifier')
|
|
33
|
+
@task = "#{two_hours} /my/command"
|
|
34
|
+
Whenever.expects(:cron).returns(@task)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
should "add the cron to the end of the file if there is no existing identifier block" do
|
|
38
|
+
existing = '# Existing crontab'
|
|
39
|
+
@command.expects(:read_crontab).at_least_once.returns(existing)
|
|
40
|
+
|
|
41
|
+
new_cron = <<-EXPECTED
|
|
42
|
+
#{existing}
|
|
43
|
+
|
|
44
|
+
# Begin Whenever generated tasks for: My identifier
|
|
45
|
+
#{@task}
|
|
46
|
+
# End Whenever generated tasks for: My identifier
|
|
47
|
+
EXPECTED
|
|
48
|
+
|
|
49
|
+
assert_equal new_cron, @command.send(:updated_crontab)
|
|
50
|
+
|
|
51
|
+
@command.expects(:write_crontab).with(new_cron).returns(true)
|
|
52
|
+
assert @command.run
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
should "replace an existing block if the identifier matches" do
|
|
56
|
+
existing = <<-EXISTING_CRON
|
|
57
|
+
# Something
|
|
58
|
+
|
|
59
|
+
# Begin Whenever generated tasks for: My identifier
|
|
60
|
+
My whenever job that was already here
|
|
61
|
+
# End Whenever generated tasks for: My identifier
|
|
62
|
+
|
|
63
|
+
# Begin Whenever generated tasks for: Other identifier
|
|
64
|
+
This shouldn't get replaced
|
|
65
|
+
# End Whenever generated tasks for: Other identifier
|
|
66
|
+
EXISTING_CRON
|
|
67
|
+
|
|
68
|
+
@command.expects(:read_crontab).at_least_once.returns(existing)
|
|
69
|
+
|
|
70
|
+
new_cron = <<-NEW_CRON
|
|
71
|
+
# Something
|
|
72
|
+
|
|
73
|
+
# Begin Whenever generated tasks for: My identifier
|
|
74
|
+
#{@task}
|
|
75
|
+
# End Whenever generated tasks for: My identifier
|
|
76
|
+
|
|
77
|
+
# Begin Whenever generated tasks for: Other identifier
|
|
78
|
+
This shouldn't get replaced
|
|
79
|
+
# End Whenever generated tasks for: Other identifier
|
|
80
|
+
NEW_CRON
|
|
81
|
+
|
|
82
|
+
assert_equal new_cron, @command.send(:updated_crontab)
|
|
83
|
+
|
|
84
|
+
@command.expects(:write_crontab).with(new_cron).returns(true)
|
|
85
|
+
assert @command.run
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
context "A command line delete" do
|
|
90
|
+
setup do
|
|
91
|
+
File.expects(:exists?).with('config/schedule.rb').returns(true)
|
|
92
|
+
@command = Whenever::CommandLine.new(:clear => true, :identifier => 'My identifier')
|
|
93
|
+
@task = "#{two_hours} /my/command"
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
should "add an empty identifier block if there is no existing one" do
|
|
97
|
+
existing = '# Existing crontab'
|
|
98
|
+
@command.expects(:read_crontab).at_least_once.returns(existing)
|
|
99
|
+
|
|
100
|
+
new_cron = <<-EXPECTED
|
|
101
|
+
#{existing}
|
|
102
|
+
|
|
103
|
+
# Begin Whenever generated tasks for: My identifier
|
|
104
|
+
# End Whenever generated tasks for: My identifier
|
|
105
|
+
EXPECTED
|
|
106
|
+
|
|
107
|
+
assert_equal new_cron, @command.send(:updated_crontab)
|
|
108
|
+
|
|
109
|
+
@command.expects(:write_crontab).with(new_cron).returns(true)
|
|
110
|
+
assert @command.run
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
should "delete an existing block if the identifier matches" do
|
|
114
|
+
existing = <<-EXISTING_CRON
|
|
115
|
+
# Something
|
|
116
|
+
|
|
117
|
+
# Begin Whenever generated tasks for: My identifier
|
|
118
|
+
My whenever job that was already here
|
|
119
|
+
# End Whenever generated tasks for: My identifier
|
|
120
|
+
|
|
121
|
+
# Begin Whenever generated tasks for: Other identifier
|
|
122
|
+
This shouldn't get replaced
|
|
123
|
+
# End Whenever generated tasks for: Other identifier
|
|
124
|
+
EXISTING_CRON
|
|
125
|
+
|
|
126
|
+
@command.expects(:read_crontab).at_least_once.returns(existing)
|
|
127
|
+
|
|
128
|
+
new_cron = <<-NEW_CRON
|
|
129
|
+
# Something
|
|
130
|
+
|
|
131
|
+
# Begin Whenever generated tasks for: My identifier
|
|
132
|
+
# End Whenever generated tasks for: My identifier
|
|
133
|
+
|
|
134
|
+
# Begin Whenever generated tasks for: Other identifier
|
|
135
|
+
This shouldn't get replaced
|
|
136
|
+
# End Whenever generated tasks for: Other identifier
|
|
137
|
+
NEW_CRON
|
|
138
|
+
|
|
139
|
+
assert_equal new_cron, @command.send(:updated_crontab)
|
|
140
|
+
|
|
141
|
+
@command.expects(:write_crontab).with(new_cron).returns(true)
|
|
142
|
+
assert @command.run
|
|
143
|
+
end
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
context "A command line update with no identifier" do
|
|
147
|
+
setup do
|
|
148
|
+
File.expects(:exists?).with('config/schedule.rb').returns(true)
|
|
149
|
+
Whenever::CommandLine.any_instance.expects(:default_identifier).returns('DEFAULT')
|
|
150
|
+
@command = Whenever::CommandLine.new(:update => true, :file => @file)
|
|
151
|
+
end
|
|
152
|
+
|
|
153
|
+
should "use the default identifier" do
|
|
154
|
+
assert_equal "Whenever generated tasks for: DEFAULT", @command.send(:comment_base)
|
|
155
|
+
end
|
|
156
|
+
end
|
|
157
|
+
|
|
158
|
+
context "combined params" do
|
|
159
|
+
setup do
|
|
160
|
+
Whenever::CommandLine.any_instance.expects(:exit)
|
|
161
|
+
Whenever::CommandLine.any_instance.expects(:warn)
|
|
162
|
+
File.expects(:exists?).with('config/schedule.rb').returns(true)
|
|
163
|
+
end
|
|
164
|
+
|
|
165
|
+
should "exit with write and clear" do
|
|
166
|
+
@command = Whenever::CommandLine.new(:write => true, :clear => true)
|
|
167
|
+
end
|
|
168
|
+
|
|
169
|
+
should "exit with write and update" do
|
|
170
|
+
@command = Whenever::CommandLine.new(:write => true, :update => true)
|
|
171
|
+
end
|
|
172
|
+
|
|
173
|
+
should "exit with update and clear" do
|
|
174
|
+
@command = Whenever::CommandLine.new(:update => true, :clear => true)
|
|
175
|
+
end
|
|
176
|
+
end
|
|
177
|
+
|
|
178
|
+
context "A runner where the environment is overridden using the :set option" do
|
|
179
|
+
setup do
|
|
180
|
+
@output = Whenever.cron :set => 'environment=serious', :string => \
|
|
181
|
+
<<-file
|
|
182
|
+
set :environment, :silly
|
|
183
|
+
set :path, '/my/path'
|
|
184
|
+
every 2.hours do
|
|
185
|
+
runner "blahblah"
|
|
186
|
+
end
|
|
187
|
+
file
|
|
188
|
+
end
|
|
189
|
+
|
|
190
|
+
should "output the runner using the override environment" do
|
|
191
|
+
assert_match two_hours + %( cd /my/path && script/runner -e serious 'blahblah'), @output
|
|
192
|
+
end
|
|
193
|
+
end
|
|
194
|
+
|
|
195
|
+
context "A runner where the environment and path are overridden using the :set option" do
|
|
196
|
+
setup do
|
|
197
|
+
@output = Whenever.cron :set => 'environment=serious&path=/serious/path', :string => \
|
|
198
|
+
<<-file
|
|
199
|
+
set :environment, :silly
|
|
200
|
+
set :path, '/silly/path'
|
|
201
|
+
every 2.hours do
|
|
202
|
+
runner "blahblah"
|
|
203
|
+
end
|
|
204
|
+
file
|
|
205
|
+
end
|
|
206
|
+
|
|
207
|
+
should "output the runner using the overridden path and environment" do
|
|
208
|
+
assert_match two_hours + %( cd /serious/path && script/runner -e serious 'blahblah'), @output
|
|
209
|
+
end
|
|
210
|
+
end
|
|
211
|
+
|
|
212
|
+
context "A runner where the environment and path are overridden using the :set option with spaces in the string" do
|
|
213
|
+
setup do
|
|
214
|
+
@output = Whenever.cron :set => ' environment = serious& path =/serious/path', :string => \
|
|
215
|
+
<<-file
|
|
216
|
+
set :environment, :silly
|
|
217
|
+
set :path, '/silly/path'
|
|
218
|
+
every 2.hours do
|
|
219
|
+
runner "blahblah"
|
|
220
|
+
end
|
|
221
|
+
file
|
|
222
|
+
end
|
|
223
|
+
|
|
224
|
+
should "output the runner using the overridden path and environment" do
|
|
225
|
+
assert_match two_hours + %( cd /serious/path && script/runner -e serious 'blahblah'), @output
|
|
226
|
+
end
|
|
227
|
+
end
|
|
228
|
+
|
|
229
|
+
context "A runner where the environment is overridden using the :set option but no value is given" do
|
|
230
|
+
setup do
|
|
231
|
+
@output = Whenever.cron :set => ' environment=', :string => \
|
|
232
|
+
<<-file
|
|
233
|
+
set :environment, :silly
|
|
234
|
+
set :path, '/silly/path'
|
|
235
|
+
every 2.hours do
|
|
236
|
+
runner "blahblah"
|
|
237
|
+
end
|
|
238
|
+
file
|
|
239
|
+
end
|
|
240
|
+
|
|
241
|
+
should "output the runner using the original environmnet" do
|
|
242
|
+
assert_match two_hours + %( cd /silly/path && script/runner -e silly 'blahblah'), @output
|
|
243
|
+
end
|
|
244
|
+
end
|
|
245
|
+
|
|
246
|
+
context "prepare-ing the output" do
|
|
247
|
+
setup do
|
|
248
|
+
File.expects(:exists?).with('config/schedule.rb').returns(true)
|
|
249
|
+
end
|
|
250
|
+
|
|
251
|
+
should "not trim off the top lines of the file" do
|
|
252
|
+
@command = Whenever::CommandLine.new(:update => true, :identifier => 'My identifier', :cut => 0)
|
|
253
|
+
existing = <<-EXISTING_CRON
|
|
254
|
+
# Useless Comments
|
|
255
|
+
# at the top of the file
|
|
256
|
+
|
|
257
|
+
# Begin Whenever generated tasks for: My identifier
|
|
258
|
+
My whenever job that was already here
|
|
259
|
+
# End Whenever generated tasks for: My identifier
|
|
260
|
+
EXISTING_CRON
|
|
261
|
+
|
|
262
|
+
# here-doc adds an extra newline we need removed
|
|
263
|
+
assert_equal existing.strip, @command.send(:prepare, existing)
|
|
264
|
+
end
|
|
265
|
+
|
|
266
|
+
should "trim off the top lines of the file" do
|
|
267
|
+
@command = Whenever::CommandLine.new(:update => true, :identifier => 'My identifier', :cut => '3')
|
|
268
|
+
existing = <<-EXISTING_CRON
|
|
269
|
+
# Useless Comments
|
|
270
|
+
# at the top of the file
|
|
271
|
+
|
|
272
|
+
# Begin Whenever generated tasks for: My identifier
|
|
273
|
+
My whenever job that was already here
|
|
274
|
+
# End Whenever generated tasks for: My identifier
|
|
275
|
+
EXISTING_CRON
|
|
276
|
+
|
|
277
|
+
new_cron = <<-NEW_CRON
|
|
278
|
+
# Begin Whenever generated tasks for: My identifier
|
|
279
|
+
My whenever job that was already here
|
|
280
|
+
# End Whenever generated tasks for: My identifier
|
|
281
|
+
NEW_CRON
|
|
282
|
+
|
|
283
|
+
# here-doc adds an extra newline we need removed
|
|
284
|
+
assert_equal new_cron.strip, @command.send(:prepare, existing)
|
|
285
|
+
end
|
|
286
|
+
end
|
|
287
|
+
|
|
288
|
+
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
|
|
|
@@ -91,7 +91,7 @@ class OutputAtTest < Test::Unit::TestCase
|
|
|
91
91
|
end
|
|
92
92
|
|
|
93
93
|
should "output the runner using one entry because the times are aligned" do
|
|
94
|
-
assert_match
|
|
94
|
+
assert_match %(2 5,15 * * 1,3,5 cd /your/path && script/runner -e production 'blahblah'), @output
|
|
95
95
|
end
|
|
96
96
|
end
|
|
97
97
|
|
|
@@ -168,11 +168,70 @@ class OutputAtTest < Test::Unit::TestCase
|
|
|
168
168
|
|
|
169
169
|
should "output all of the commands @daily" do
|
|
170
170
|
assert_match '@daily cd /your/path && RAILS_ENV=production /usr/bin/env rake blah:blah', @output
|
|
171
|
-
assert_match
|
|
171
|
+
assert_match %(@daily cd /your/path && script/runner -e production 'runner_1'), @output
|
|
172
172
|
assert_match '@daily command_1', @output
|
|
173
|
-
assert_match
|
|
173
|
+
assert_match %(@daily cd /your/path && script/runner -e production 'runner_2'), @output
|
|
174
174
|
assert_match '@daily command_2', @output
|
|
175
175
|
end
|
|
176
176
|
end
|
|
177
177
|
|
|
178
|
+
context "every 5 minutes but but starting at 1" do
|
|
179
|
+
setup do
|
|
180
|
+
@output = Whenever.cron \
|
|
181
|
+
<<-file
|
|
182
|
+
every 5.minutes, :at => 1 do
|
|
183
|
+
command "blahblah"
|
|
184
|
+
end
|
|
185
|
+
file
|
|
186
|
+
end
|
|
187
|
+
|
|
188
|
+
should "output the command using that time" do
|
|
189
|
+
assert_match '1,6,11,16,21,26,31,36,41,46,51,56 * * * * blahblah', @output
|
|
190
|
+
end
|
|
191
|
+
end
|
|
192
|
+
|
|
193
|
+
context "every 4 minutes but starting at 2" do
|
|
194
|
+
setup do
|
|
195
|
+
@output = Whenever.cron \
|
|
196
|
+
<<-file
|
|
197
|
+
every 4.minutes, :at => 2 do
|
|
198
|
+
command "blahblah"
|
|
199
|
+
end
|
|
200
|
+
file
|
|
201
|
+
end
|
|
202
|
+
|
|
203
|
+
should "output the command using that time" do
|
|
204
|
+
assert_match '2,6,10,14,18,22,26,30,34,38,42,46,50,54,58 * * * * blahblah', @output
|
|
205
|
+
end
|
|
206
|
+
end
|
|
207
|
+
|
|
208
|
+
context "every 3 minutes but starting at 7" do
|
|
209
|
+
setup do
|
|
210
|
+
@output = Whenever.cron \
|
|
211
|
+
<<-file
|
|
212
|
+
every 3.minutes, :at => 7 do
|
|
213
|
+
command "blahblah"
|
|
214
|
+
end
|
|
215
|
+
file
|
|
216
|
+
end
|
|
217
|
+
|
|
218
|
+
should "output the command using that time" do
|
|
219
|
+
assert_match '7,10,13,16,19,22,25,28,31,34,37,40,43,46,49,52,55,58 * * * * blahblah', @output
|
|
220
|
+
end
|
|
221
|
+
end
|
|
222
|
+
|
|
223
|
+
context "every 2 minutes but starting at 27" do
|
|
224
|
+
setup do
|
|
225
|
+
@output = Whenever.cron \
|
|
226
|
+
<<-file
|
|
227
|
+
every 2.minutes, :at => 27 do
|
|
228
|
+
command "blahblah"
|
|
229
|
+
end
|
|
230
|
+
file
|
|
231
|
+
end
|
|
232
|
+
|
|
233
|
+
should "output the command using that time" do
|
|
234
|
+
assert_match '27,29,31,33,35,37,39,41,43,45,47,49,51,53,55,57,59 * * * * blahblah', @output
|
|
235
|
+
end
|
|
236
|
+
end
|
|
178
237
|
end
|
|
@@ -1,47 +1,64 @@
|
|
|
1
|
-
require File.expand_path(File.dirname(__FILE__) + "
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + "/../test_helper")
|
|
2
2
|
|
|
3
|
-
class
|
|
3
|
+
class OutputDefaultDefinedJobsTest < Test::Unit::TestCase
|
|
4
4
|
|
|
5
|
-
#
|
|
6
|
-
# only need some basic tests to ensure they are output correctly
|
|
5
|
+
# command
|
|
7
6
|
|
|
8
|
-
context "A
|
|
7
|
+
context "A plain command" do
|
|
8
|
+
setup do
|
|
9
|
+
@output = Whenever.cron \
|
|
10
|
+
<<-file
|
|
11
|
+
every 2.hours do
|
|
12
|
+
command "blahblah"
|
|
13
|
+
end
|
|
14
|
+
file
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
should "output the command" do
|
|
18
|
+
assert_match /^.+ .+ .+ .+ blahblah$/, @output
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
# runner
|
|
23
|
+
|
|
24
|
+
context "A runner with path set" do
|
|
9
25
|
setup do
|
|
10
26
|
@output = Whenever.cron \
|
|
11
27
|
<<-file
|
|
12
28
|
set :path, '/my/path'
|
|
13
29
|
every 2.hours do
|
|
14
|
-
|
|
30
|
+
runner 'blahblah'
|
|
15
31
|
end
|
|
16
32
|
file
|
|
17
33
|
end
|
|
18
34
|
|
|
19
|
-
should "output the
|
|
20
|
-
assert_match two_hours +
|
|
35
|
+
should "output the runner using that path" do
|
|
36
|
+
assert_match two_hours + %( cd /my/path && script/runner -e production 'blahblah'), @output
|
|
21
37
|
end
|
|
22
38
|
end
|
|
23
39
|
|
|
24
|
-
context "A
|
|
40
|
+
context "A runner that overrides the path set" do
|
|
25
41
|
setup do
|
|
26
42
|
@output = Whenever.cron \
|
|
27
43
|
<<-file
|
|
28
44
|
set :path, '/my/path'
|
|
29
45
|
every 2.hours do
|
|
30
|
-
|
|
46
|
+
runner "blahblah", :path => '/some/other/path'
|
|
31
47
|
end
|
|
32
48
|
file
|
|
33
49
|
end
|
|
34
50
|
|
|
35
|
-
should "output the
|
|
36
|
-
assert_match two_hours +
|
|
51
|
+
should "output the runner using that path" do
|
|
52
|
+
assert_match two_hours + %( cd /some/other/path && script/runner -e production 'blahblah'), @output
|
|
37
53
|
end
|
|
38
54
|
end
|
|
39
55
|
|
|
40
|
-
|
|
56
|
+
# rake
|
|
57
|
+
|
|
58
|
+
context "A rake command with path set" do
|
|
41
59
|
setup do
|
|
42
60
|
@output = Whenever.cron \
|
|
43
61
|
<<-file
|
|
44
|
-
set :environment, :silly
|
|
45
62
|
set :path, '/my/path'
|
|
46
63
|
every 2.hours do
|
|
47
64
|
rake "blahblah"
|
|
@@ -49,25 +66,24 @@ class OutputRakeTest < Test::Unit::TestCase
|
|
|
49
66
|
file
|
|
50
67
|
end
|
|
51
68
|
|
|
52
|
-
should "output the rake command using that
|
|
53
|
-
assert_match two_hours + ' cd /my/path && RAILS_ENV=
|
|
69
|
+
should "output the rake command using that path" do
|
|
70
|
+
assert_match two_hours + ' cd /my/path && RAILS_ENV=production /usr/bin/env rake blahblah', @output
|
|
54
71
|
end
|
|
55
72
|
end
|
|
56
73
|
|
|
57
|
-
context "A rake command that overrides the
|
|
74
|
+
context "A rake command that overrides the path set" do
|
|
58
75
|
setup do
|
|
59
76
|
@output = Whenever.cron \
|
|
60
77
|
<<-file
|
|
61
|
-
set :environment, :silly
|
|
62
78
|
set :path, '/my/path'
|
|
63
79
|
every 2.hours do
|
|
64
|
-
rake "blahblah", :
|
|
80
|
+
rake "blahblah", :path => '/some/other/path'
|
|
65
81
|
end
|
|
66
82
|
file
|
|
67
83
|
end
|
|
68
84
|
|
|
69
|
-
should "output the rake command using that
|
|
70
|
-
assert_match two_hours + ' cd /
|
|
85
|
+
should "output the rake command using that path" do
|
|
86
|
+
assert_match two_hours + ' cd /some/other/path && RAILS_ENV=production /usr/bin/env rake blahblah', @output
|
|
71
87
|
end
|
|
72
88
|
end
|
|
73
89
|
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + "/../test_helper")
|
|
2
|
+
|
|
3
|
+
class OutputDefinedJobTest < Test::Unit::TestCase
|
|
4
|
+
|
|
5
|
+
context "A defined job with a :task" do
|
|
6
|
+
setup do
|
|
7
|
+
@output = Whenever.cron \
|
|
8
|
+
<<-file
|
|
9
|
+
job_type :some_job, "before :task after"
|
|
10
|
+
every 2.hours do
|
|
11
|
+
some_job "during"
|
|
12
|
+
end
|
|
13
|
+
file
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
should "output the defined job with the task" do
|
|
17
|
+
assert_match /^.+ .+ .+ .+ before during after$/, @output
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
context "A defined job with a :task and some options" do
|
|
22
|
+
setup do
|
|
23
|
+
@output = Whenever.cron \
|
|
24
|
+
<<-file
|
|
25
|
+
job_type :some_job, "before :task after :option1 :option2"
|
|
26
|
+
every 2.hours do
|
|
27
|
+
some_job "during", :option1 => 'happy', :option2 => 'birthday'
|
|
28
|
+
end
|
|
29
|
+
file
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
should "output the defined job with the task and options" do
|
|
33
|
+
assert_match /^.+ .+ .+ .+ before during after happy birthday$/, @output
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
context "A defined job with a :task and an option where the option is set globally" do
|
|
38
|
+
setup do
|
|
39
|
+
@output = Whenever.cron \
|
|
40
|
+
<<-file
|
|
41
|
+
job_type :some_job, "before :task after :option1"
|
|
42
|
+
set :option1, 'happy'
|
|
43
|
+
every 2.hours do
|
|
44
|
+
some_job "during"
|
|
45
|
+
end
|
|
46
|
+
file
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
should "output the defined job with the task and options" do
|
|
50
|
+
assert_match /^.+ .+ .+ .+ before during after happy$/, @output
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
context "A defined job with a :task and an option where the option is set globally and locally" do
|
|
55
|
+
setup do
|
|
56
|
+
@output = Whenever.cron \
|
|
57
|
+
<<-file
|
|
58
|
+
job_type :some_job, "before :task after :option1"
|
|
59
|
+
set :option1, 'global'
|
|
60
|
+
every 2.hours do
|
|
61
|
+
some_job "during", :option1 => 'local'
|
|
62
|
+
end
|
|
63
|
+
file
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
should "output the defined job using the local option" do
|
|
67
|
+
assert_match /^.+ .+ .+ .+ before during after local$/, @output
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
context "A defined job with a :task and an option that is not set" do
|
|
72
|
+
setup do
|
|
73
|
+
@output = Whenever.cron \
|
|
74
|
+
<<-file
|
|
75
|
+
job_type :some_job, "before :task after :option1"
|
|
76
|
+
every 2.hours do
|
|
77
|
+
some_job "during", :option2 => 'happy'
|
|
78
|
+
end
|
|
79
|
+
file
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
should "output the defined job with that option removed" do
|
|
83
|
+
assert_match /^.+ .+ .+ .+ before during after$/, @output
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
context "A defined job that uses a :path where none is explicitly set" do
|
|
88
|
+
setup do
|
|
89
|
+
Whenever.expects(:path).returns('/my/path')
|
|
90
|
+
|
|
91
|
+
@output = Whenever.cron \
|
|
92
|
+
<<-file
|
|
93
|
+
job_type :some_job, "cd :path && :task"
|
|
94
|
+
every 2.hours do
|
|
95
|
+
some_job 'blahblah'
|
|
96
|
+
end
|
|
97
|
+
file
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
should "default to using the Whenever.path" do
|
|
101
|
+
assert_match two_hours + %( cd /my/path && blahblah), @output
|
|
102
|
+
end
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
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 OutputRedirectionTest < Test::Unit::TestCase
|
|
4
4
|
|
|
@@ -46,7 +46,7 @@ class OutputRedirectionTest < Test::Unit::TestCase
|
|
|
46
46
|
end
|
|
47
47
|
|
|
48
48
|
should "output the command without the log syntax appended" do
|
|
49
|
-
assert_match /^.+ .+ .+ .+ blahblah >> dev_null 2
|
|
49
|
+
assert_match /^.+ .+ .+ .+ blahblah >> dev_null 2>> dev_err$/, @output
|
|
50
50
|
end
|
|
51
51
|
end
|
|
52
52
|
|
|
@@ -80,7 +80,7 @@ class OutputRedirectionTest < Test::Unit::TestCase
|
|
|
80
80
|
|
|
81
81
|
should "output the command with the overridden redirection syntax appended" do
|
|
82
82
|
assert_no_match /.+ .+ .+ .+ blahblah >> logfile.log 2>&1/, @output
|
|
83
|
-
assert_match /^.+ .+ .+ .+ blahblah >> dev_null 2
|
|
83
|
+
assert_match /^.+ .+ .+ .+ blahblah >> dev_null 2>> dev_err$/, @output
|
|
84
84
|
end
|
|
85
85
|
end
|
|
86
86
|
|
|
@@ -130,7 +130,7 @@ class OutputRedirectionTest < Test::Unit::TestCase
|
|
|
130
130
|
end
|
|
131
131
|
|
|
132
132
|
should "output the command without the redirection syntax appended" do
|
|
133
|
-
assert_match /^.+ .+ .+ .+ blahblah >> dev_null 2
|
|
133
|
+
assert_match /^.+ .+ .+ .+ blahblah >> dev_null 2>> dev_err$/, @output
|
|
134
134
|
end
|
|
135
135
|
end
|
|
136
136
|
|
|
@@ -145,8 +145,8 @@ class OutputRedirectionTest < Test::Unit::TestCase
|
|
|
145
145
|
file
|
|
146
146
|
end
|
|
147
147
|
|
|
148
|
-
should "output the command without the standard
|
|
149
|
-
assert_match /^.+ .+ .+ .+ blahblah 2
|
|
148
|
+
should "output the command without the standard error syntax appended" do
|
|
149
|
+
assert_match /^.+ .+ .+ .+ blahblah 2>> dev_null$/, @output
|
|
150
150
|
end
|
|
151
151
|
end
|
|
152
152
|
|
|
@@ -177,7 +177,7 @@ class OutputRedirectionTest < Test::Unit::TestCase
|
|
|
177
177
|
end
|
|
178
178
|
|
|
179
179
|
should "output the command without the log syntax appended" do
|
|
180
|
-
assert_match /^.+ .+ .+ .+ blahblah 2
|
|
180
|
+
assert_match /^.+ .+ .+ .+ blahblah 2>> dev_err$/, @output
|
|
181
181
|
end
|
|
182
182
|
end
|
|
183
183
|
|
|
@@ -207,7 +207,7 @@ class OutputRedirectionTest < Test::Unit::TestCase
|
|
|
207
207
|
end
|
|
208
208
|
|
|
209
209
|
should "output the command with stdout directed to /dev/null" do
|
|
210
|
-
assert_match /^.+ .+ .+ .+ blahblah
|
|
210
|
+
assert_match /^.+ .+ .+ .+ blahblah > \/dev\/null$/, @output
|
|
211
211
|
end
|
|
212
212
|
end
|
|
213
213
|
|
|
@@ -237,7 +237,7 @@ class OutputRedirectionTest < Test::Unit::TestCase
|
|
|
237
237
|
end
|
|
238
238
|
|
|
239
239
|
should "output the command with stderr directed to /dev/null" do
|
|
240
|
-
assert_match /^.+ .+ .+ .+ blahblah
|
|
240
|
+
assert_match /^.+ .+ .+ .+ blahblah > \/dev\/null 2>&1$/, @output
|
|
241
241
|
end
|
|
242
242
|
end
|
|
243
243
|
|
|
@@ -267,7 +267,7 @@ class OutputRedirectionTest < Test::Unit::TestCase
|
|
|
267
267
|
end
|
|
268
268
|
|
|
269
269
|
should "output the command with stderr directed to /dev/null" do
|
|
270
|
-
assert_match /^.+ .+ .+ .+ blahblah >> \/dev\/null 2
|
|
270
|
+
assert_match /^.+ .+ .+ .+ blahblah >> \/dev\/null 2>> my_error.log$/, @output
|
|
271
271
|
end
|
|
272
272
|
end
|
|
273
273
|
|
|
@@ -286,4 +286,4 @@ class OutputRedirectionTest < Test::Unit::TestCase
|
|
|
286
286
|
assert_match /^.+ .+ .+ .+ blahblah >> cron.log 2>&1$/, @output
|
|
287
287
|
end
|
|
288
288
|
end
|
|
289
|
-
end
|
|
289
|
+
end
|