whenever 1.1.3 → 1.1.4
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -0
- data/lib/whenever/version.rb +1 -1
- data/whenever.gemspec +1 -2
- metadata +3 -33
- data/test/functional/command_line_test.rb +0 -458
- data/test/functional/output_at_test.rb +0 -246
- data/test/functional/output_default_defined_jobs_test.rb +0 -310
- data/test/functional/output_defined_job_test.rb +0 -113
- data/test/functional/output_description_test.rb +0 -25
- data/test/functional/output_env_test.rb +0 -29
- data/test/functional/output_jobs_for_roles_test.rb +0 -65
- data/test/functional/output_jobs_with_mailto_test.rb +0 -168
- data/test/functional/output_jobs_with_sequence_test.rb +0 -187
- data/test/functional/output_redirection_test.rb +0 -248
- data/test/test_case.rb +0 -32
- data/test/test_helper.rb +0 -51
- data/test/unit/capistrano_support_test.rb +0 -147
- data/test/unit/cron_test.rb +0 -418
- data/test/unit/executable_test.rb +0 -142
- data/test/unit/job_test.rb +0 -114
|
@@ -1,246 +0,0 @@
|
|
|
1
|
-
require 'test_helper'
|
|
2
|
-
|
|
3
|
-
class OutputAtTest < Whenever::TestCase
|
|
4
|
-
test "weekday at a (single) given time" do
|
|
5
|
-
output = Whenever.cron \
|
|
6
|
-
<<-file
|
|
7
|
-
set :job_template, nil
|
|
8
|
-
every "weekday", :at => '5:02am' do
|
|
9
|
-
command "blahblah"
|
|
10
|
-
end
|
|
11
|
-
file
|
|
12
|
-
|
|
13
|
-
assert_match '2 5 * * 1-5 blahblah', output
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
test "weekday at a multiple diverse times, via an array" do
|
|
17
|
-
output = Whenever.cron \
|
|
18
|
-
<<-file
|
|
19
|
-
set :job_template, nil
|
|
20
|
-
every "weekday", :at => %w(5:02am 3:52pm) do
|
|
21
|
-
command "blahblah"
|
|
22
|
-
end
|
|
23
|
-
file
|
|
24
|
-
|
|
25
|
-
assert_match '2 5 * * 1-5 blahblah', output
|
|
26
|
-
assert_match '52 15 * * 1-5 blahblah', output
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
test "weekday at a multiple diverse times, comma separated" do
|
|
30
|
-
output = Whenever.cron \
|
|
31
|
-
<<-file
|
|
32
|
-
set :job_template, nil
|
|
33
|
-
every "weekday", :at => '5:02am, 3:52pm' do
|
|
34
|
-
command "blahblah"
|
|
35
|
-
end
|
|
36
|
-
file
|
|
37
|
-
|
|
38
|
-
assert_match '2 5 * * 1-5 blahblah', output
|
|
39
|
-
assert_match '52 15 * * 1-5 blahblah', output
|
|
40
|
-
end
|
|
41
|
-
|
|
42
|
-
test "weekday at a multiple aligned times" do
|
|
43
|
-
output = Whenever.cron \
|
|
44
|
-
<<-file
|
|
45
|
-
set :job_template, nil
|
|
46
|
-
every "weekday", :at => '5:02am, 3:02pm' do
|
|
47
|
-
command "blahblah"
|
|
48
|
-
end
|
|
49
|
-
file
|
|
50
|
-
|
|
51
|
-
assert_match '2 5,15 * * 1-5 blahblah', output
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
test "various days at a various aligned times" do
|
|
55
|
-
output = Whenever.cron \
|
|
56
|
-
<<-file
|
|
57
|
-
set :job_template, nil
|
|
58
|
-
every "mon,wed,fri", :at => '5:02am, 3:02pm' do
|
|
59
|
-
command "blahblah"
|
|
60
|
-
end
|
|
61
|
-
file
|
|
62
|
-
|
|
63
|
-
assert_match '2 5,15 * * 1,3,5 blahblah', output
|
|
64
|
-
end
|
|
65
|
-
|
|
66
|
-
test "various days at a various aligned times using a runner" do
|
|
67
|
-
output = Whenever.cron \
|
|
68
|
-
<<-file
|
|
69
|
-
set :job_template, nil
|
|
70
|
-
set :path, '/your/path'
|
|
71
|
-
every "mon,wed,fri", :at => '5:02am, 3:02pm' do
|
|
72
|
-
runner "Worker.perform_async(1.day.ago)"
|
|
73
|
-
end
|
|
74
|
-
file
|
|
75
|
-
|
|
76
|
-
assert_match %(2 5,15 * * 1,3,5 cd /your/path && bundle exec script/runner -e production 'Worker.perform_async(1.day.ago)'), output
|
|
77
|
-
end
|
|
78
|
-
|
|
79
|
-
test "various days at a various aligned times using a rake task" do
|
|
80
|
-
output = Whenever.cron \
|
|
81
|
-
<<-file
|
|
82
|
-
set :job_template, nil
|
|
83
|
-
set :path, '/your/path'
|
|
84
|
-
every "mon,wed,fri", :at => '5:02am, 3:02pm' do
|
|
85
|
-
rake "blah:blah"
|
|
86
|
-
end
|
|
87
|
-
file
|
|
88
|
-
|
|
89
|
-
assert_match '2 5,15 * * 1,3,5 cd /your/path && RAILS_ENV=production bundle exec rake blah:blah --silent', output
|
|
90
|
-
end
|
|
91
|
-
|
|
92
|
-
test "A command every 1.month at very diverse times" do
|
|
93
|
-
output = Whenever.cron \
|
|
94
|
-
<<-file
|
|
95
|
-
set :job_template, nil
|
|
96
|
-
every [1.month, 1.day], :at => 'january 5:02am, june 17th at 2:22pm, june 3rd at 3:33am' do
|
|
97
|
-
command "blahblah"
|
|
98
|
-
end
|
|
99
|
-
file
|
|
100
|
-
|
|
101
|
-
# The 1.month commands
|
|
102
|
-
assert_match '2 5 1 * * blahblah', output
|
|
103
|
-
assert_match '22 14 17 * * blahblah', output
|
|
104
|
-
assert_match '33 3 3 * * blahblah', output
|
|
105
|
-
|
|
106
|
-
# The 1.day commands
|
|
107
|
-
assert_match '2 5 * * * blahblah', output
|
|
108
|
-
assert_match '22 14 * * * blahblah', output
|
|
109
|
-
assert_match '33 3 * * * blahblah', output
|
|
110
|
-
end
|
|
111
|
-
|
|
112
|
-
test "Multiple commands output every :reboot" do
|
|
113
|
-
output = Whenever.cron \
|
|
114
|
-
<<-file
|
|
115
|
-
set :job_template, nil
|
|
116
|
-
every :reboot do
|
|
117
|
-
command "command_1"
|
|
118
|
-
command "command_2"
|
|
119
|
-
end
|
|
120
|
-
file
|
|
121
|
-
|
|
122
|
-
assert_match "@reboot command_1", output
|
|
123
|
-
assert_match "@reboot command_2", output
|
|
124
|
-
end
|
|
125
|
-
|
|
126
|
-
test "Many different job types output every :day" do
|
|
127
|
-
output = Whenever.cron \
|
|
128
|
-
<<-file
|
|
129
|
-
set :job_template, nil
|
|
130
|
-
set :path, '/your/path'
|
|
131
|
-
every :daily do
|
|
132
|
-
rake "blah:blah"
|
|
133
|
-
runner "runner_1"
|
|
134
|
-
command "command_1"
|
|
135
|
-
runner "runner_2"
|
|
136
|
-
command "command_2"
|
|
137
|
-
end
|
|
138
|
-
file
|
|
139
|
-
|
|
140
|
-
assert_match '@daily cd /your/path && RAILS_ENV=production bundle exec rake blah:blah --silent', output
|
|
141
|
-
assert_match %(@daily cd /your/path && bundle exec script/runner -e production 'runner_1'), output
|
|
142
|
-
assert_match '@daily command_1', output
|
|
143
|
-
assert_match %(@daily cd /your/path && bundle exec script/runner -e production 'runner_2'), output
|
|
144
|
-
assert_match '@daily command_2', output
|
|
145
|
-
end
|
|
146
|
-
|
|
147
|
-
test "every 5 minutes but but starting at 1" do
|
|
148
|
-
output = Whenever.cron \
|
|
149
|
-
<<-file
|
|
150
|
-
set :job_template, nil
|
|
151
|
-
every 5.minutes, :at => 1 do
|
|
152
|
-
command "blahblah"
|
|
153
|
-
end
|
|
154
|
-
file
|
|
155
|
-
|
|
156
|
-
assert_match '1,6,11,16,21,26,31,36,41,46,51,56 * * * * blahblah', output
|
|
157
|
-
end
|
|
158
|
-
|
|
159
|
-
test "every 4 minutes but starting at 2" do
|
|
160
|
-
output = Whenever.cron \
|
|
161
|
-
<<-file
|
|
162
|
-
set :job_template, nil
|
|
163
|
-
every 4.minutes, :at => 2 do
|
|
164
|
-
command "blahblah"
|
|
165
|
-
end
|
|
166
|
-
file
|
|
167
|
-
|
|
168
|
-
assert_match '2,6,10,14,18,22,26,30,34,38,42,46,50,54,58 * * * * blahblah', output
|
|
169
|
-
end
|
|
170
|
-
|
|
171
|
-
test "every 3 minutes but starting at 7" do
|
|
172
|
-
output = Whenever.cron \
|
|
173
|
-
<<-file
|
|
174
|
-
set :job_template, nil
|
|
175
|
-
every 3.minutes, :at => 7 do
|
|
176
|
-
command "blahblah"
|
|
177
|
-
end
|
|
178
|
-
file
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
assert_match '7,10,13,16,19,22,25,28,31,34,37,40,43,46,49,52,55,58 * * * * blahblah', output
|
|
182
|
-
end
|
|
183
|
-
|
|
184
|
-
test "every 2 minutes but starting at 27" do
|
|
185
|
-
output = Whenever.cron \
|
|
186
|
-
<<-file
|
|
187
|
-
set :job_template, nil
|
|
188
|
-
every 2.minutes, :at => 27 do
|
|
189
|
-
command "blahblah"
|
|
190
|
-
end
|
|
191
|
-
file
|
|
192
|
-
|
|
193
|
-
assert_match '27,29,31,33,35,37,39,41,43,45,47,49,51,53,55,57,59 * * * * blahblah', output
|
|
194
|
-
end
|
|
195
|
-
|
|
196
|
-
test "using raw cron syntax" do
|
|
197
|
-
output = Whenever.cron \
|
|
198
|
-
<<-file
|
|
199
|
-
set :job_template, nil
|
|
200
|
-
every '0 0 27,31 * *' do
|
|
201
|
-
command "blahblah"
|
|
202
|
-
end
|
|
203
|
-
file
|
|
204
|
-
|
|
205
|
-
assert_match '0 0 27,31 * * blahblah', output
|
|
206
|
-
end
|
|
207
|
-
|
|
208
|
-
test "using custom Chronic configuration to specify time using 24 hour clock" do
|
|
209
|
-
output = Whenever.cron \
|
|
210
|
-
<<-file
|
|
211
|
-
set :job_template, nil
|
|
212
|
-
set :chronic_options, :hours24 => true
|
|
213
|
-
every 1.day, :at => '03:00' do
|
|
214
|
-
command "blahblah"
|
|
215
|
-
end
|
|
216
|
-
file
|
|
217
|
-
|
|
218
|
-
assert_match '0 3 * * * blahblah', output
|
|
219
|
-
end
|
|
220
|
-
|
|
221
|
-
test "using custom Chronic configuration to specify date using little endian preference" do
|
|
222
|
-
output = Whenever.cron \
|
|
223
|
-
<<-file
|
|
224
|
-
set :job_template, nil
|
|
225
|
-
set :chronic_options, :endian_precedence => :little
|
|
226
|
-
every 1.month, :at => '02/03 10:15' do
|
|
227
|
-
command "blahblah"
|
|
228
|
-
end
|
|
229
|
-
file
|
|
230
|
-
|
|
231
|
-
assert_match '15 10 2 * * blahblah', output
|
|
232
|
-
end
|
|
233
|
-
|
|
234
|
-
test "using custom Chronic configuration to specify time using 24 hour clock and date using little endian preference" do
|
|
235
|
-
output = Whenever.cron \
|
|
236
|
-
<<-file
|
|
237
|
-
set :job_template, nil
|
|
238
|
-
set :chronic_options, :hours24 => true, :endian_precedence => :little
|
|
239
|
-
every 1.month, :at => '01/02 04:30' do
|
|
240
|
-
command "blahblah"
|
|
241
|
-
end
|
|
242
|
-
file
|
|
243
|
-
|
|
244
|
-
assert_match '30 4 1 * * blahblah', output
|
|
245
|
-
end
|
|
246
|
-
end
|
|
@@ -1,310 +0,0 @@
|
|
|
1
|
-
require 'test_helper'
|
|
2
|
-
|
|
3
|
-
class OutputDefaultDefinedJobsTest < Whenever::TestCase
|
|
4
|
-
|
|
5
|
-
# command
|
|
6
|
-
|
|
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
|
|
15
|
-
|
|
16
|
-
assert_match(/^.+ .+ .+ .+ blahblah$/, output)
|
|
17
|
-
end
|
|
18
|
-
|
|
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
|
|
26
|
-
|
|
27
|
-
assert_match(/^.+ .+ .+ .+ \/bin\/bash -l -c 'blahblah'$/, output)
|
|
28
|
-
end
|
|
29
|
-
|
|
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)
|
|
41
|
-
end
|
|
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
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
assert_match(/^.+ .+ .+ .+ \/bin\/sh -l -c 'blahblah'$/, output)
|
|
54
|
-
assert_no_match(/bash/, output)
|
|
55
|
-
end
|
|
56
|
-
|
|
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
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
assert_match(/^.+ .+ .+ .+ \/bin\/sh -l -c 'cd \/tmp && blahblah'$/, output)
|
|
69
|
-
assert_no_match(/bash/, output)
|
|
70
|
-
end
|
|
71
|
-
|
|
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'
|
|
78
|
-
every 2.hours do
|
|
79
|
-
command "blahblah"
|
|
80
|
-
end
|
|
81
|
-
end
|
|
82
|
-
file
|
|
83
|
-
|
|
84
|
-
assert_match(/blahblah/, output)
|
|
85
|
-
end
|
|
86
|
-
|
|
87
|
-
# runner
|
|
88
|
-
|
|
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
|
|
100
|
-
end
|
|
101
|
-
|
|
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
|
|
114
|
-
|
|
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
|
|
127
|
-
end
|
|
128
|
-
|
|
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
|
|
142
|
-
|
|
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
|
|
155
|
-
end
|
|
156
|
-
|
|
157
|
-
# rake
|
|
158
|
-
|
|
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
|
|
170
|
-
end
|
|
171
|
-
|
|
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
|
|
183
|
-
end
|
|
184
|
-
|
|
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
|
|
197
|
-
end
|
|
198
|
-
|
|
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
|
|
210
|
-
end
|
|
211
|
-
|
|
212
|
-
test "A rake command that uses the default environment variable when RAILS_ENV is set" do
|
|
213
|
-
ENV.expects(:fetch).with("RAILS_ENV", "production").returns("development")
|
|
214
|
-
output = Whenever.cron \
|
|
215
|
-
<<-file
|
|
216
|
-
set :job_template, nil
|
|
217
|
-
set :path, '/my/path'
|
|
218
|
-
every 2.hours do
|
|
219
|
-
rake "blahblah"
|
|
220
|
-
end
|
|
221
|
-
file
|
|
222
|
-
|
|
223
|
-
assert_match two_hours + ' cd /my/path && RAILS_ENV=development bundle exec rake blahblah --silent', output
|
|
224
|
-
end
|
|
225
|
-
|
|
226
|
-
test "A rake command that sets 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"
|
|
234
|
-
end
|
|
235
|
-
file
|
|
236
|
-
|
|
237
|
-
assert_match two_hours + ' cd /my/path && RAKE_ENV=production bundle exec rake blahblah --silent', output
|
|
238
|
-
end
|
|
239
|
-
|
|
240
|
-
test "A rake command that overrides the environment variable" do
|
|
241
|
-
output = Whenever.cron \
|
|
242
|
-
<<-file
|
|
243
|
-
set :job_template, nil
|
|
244
|
-
set :path, '/my/path'
|
|
245
|
-
set :environment_variable, 'RAKE_ENV'
|
|
246
|
-
every 2.hours do
|
|
247
|
-
rake "blahblah", :environment_variable => 'SOME_ENV'
|
|
248
|
-
end
|
|
249
|
-
file
|
|
250
|
-
|
|
251
|
-
assert_match two_hours + ' cd /my/path && SOME_ENV=production bundle exec rake blahblah --silent', output
|
|
252
|
-
end
|
|
253
|
-
|
|
254
|
-
# script
|
|
255
|
-
|
|
256
|
-
test "A script command with path set" do
|
|
257
|
-
output = Whenever.cron \
|
|
258
|
-
<<-file
|
|
259
|
-
set :job_template, nil
|
|
260
|
-
set :path, '/my/path'
|
|
261
|
-
every 2.hours do
|
|
262
|
-
script "blahblah"
|
|
263
|
-
end
|
|
264
|
-
file
|
|
265
|
-
|
|
266
|
-
assert_match two_hours + ' cd /my/path && RAILS_ENV=production bundle exec script/blahblah', output
|
|
267
|
-
end
|
|
268
|
-
|
|
269
|
-
test "A script command for a non-bundler app" do
|
|
270
|
-
Whenever.expects(:path).at_least_once.returns('/my/path')
|
|
271
|
-
Whenever.expects(:bundler?).returns(false)
|
|
272
|
-
output = Whenever.cron \
|
|
273
|
-
<<-file
|
|
274
|
-
set :job_template, nil
|
|
275
|
-
every 2.hours do
|
|
276
|
-
script 'blahblah'
|
|
277
|
-
end
|
|
278
|
-
file
|
|
279
|
-
|
|
280
|
-
assert_match two_hours + ' cd /my/path && RAILS_ENV=production script/blahblah', output
|
|
281
|
-
end
|
|
282
|
-
|
|
283
|
-
test "A script command that uses output" do
|
|
284
|
-
output = Whenever.cron \
|
|
285
|
-
<<-file
|
|
286
|
-
set :job_template, nil
|
|
287
|
-
set :output, '/log/file'
|
|
288
|
-
set :path, '/my/path'
|
|
289
|
-
every 2.hours do
|
|
290
|
-
script "blahblah", :path => '/some/other/path'
|
|
291
|
-
end
|
|
292
|
-
file
|
|
293
|
-
|
|
294
|
-
assert_match two_hours + ' cd /some/other/path && RAILS_ENV=production bundle exec script/blahblah >> /log/file 2>&1', output
|
|
295
|
-
end
|
|
296
|
-
|
|
297
|
-
test "A script command that uses an environment variable" do
|
|
298
|
-
output = Whenever.cron \
|
|
299
|
-
<<-file
|
|
300
|
-
set :job_template, nil
|
|
301
|
-
set :environment_variable, 'RAKE_ENV'
|
|
302
|
-
set :path, '/my/path'
|
|
303
|
-
every 2.hours do
|
|
304
|
-
script "blahblah"
|
|
305
|
-
end
|
|
306
|
-
file
|
|
307
|
-
|
|
308
|
-
assert_match two_hours + ' cd /my/path && RAKE_ENV=production bundle exec script/blahblah', output
|
|
309
|
-
end
|
|
310
|
-
end
|
|
@@ -1,113 +0,0 @@
|
|
|
1
|
-
require 'test_helper'
|
|
2
|
-
|
|
3
|
-
class OutputDefinedJobTest < Whenever::TestCase
|
|
4
|
-
test "defined job with a :task" do
|
|
5
|
-
output = Whenever.cron \
|
|
6
|
-
<<-file
|
|
7
|
-
set :job_template, nil
|
|
8
|
-
job_type :some_job, "before :task after"
|
|
9
|
-
every 2.hours do
|
|
10
|
-
some_job "during"
|
|
11
|
-
end
|
|
12
|
-
file
|
|
13
|
-
|
|
14
|
-
assert_match(/^.+ .+ .+ .+ before during after$/, output)
|
|
15
|
-
end
|
|
16
|
-
|
|
17
|
-
test "defined job with a :task and some options" do
|
|
18
|
-
output = Whenever.cron \
|
|
19
|
-
<<-file
|
|
20
|
-
set :job_template, nil
|
|
21
|
-
job_type :some_job, "before :task after :option1 :option2"
|
|
22
|
-
every 2.hours do
|
|
23
|
-
some_job "during", :option1 => 'happy', :option2 => 'birthday'
|
|
24
|
-
end
|
|
25
|
-
file
|
|
26
|
-
|
|
27
|
-
assert_match(/^.+ .+ .+ .+ before during after happy birthday$/, output)
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
test "defined job with a :task and an option where the option is set globally" do
|
|
31
|
-
output = Whenever.cron \
|
|
32
|
-
<<-file
|
|
33
|
-
set :job_template, nil
|
|
34
|
-
job_type :some_job, "before :task after :option1"
|
|
35
|
-
set :option1, 'happy'
|
|
36
|
-
every 2.hours do
|
|
37
|
-
some_job "during"
|
|
38
|
-
end
|
|
39
|
-
file
|
|
40
|
-
|
|
41
|
-
assert_match(/^.+ .+ .+ .+ before during after happy$/, output)
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
test "defined job with a :task and an option where the option is set globally and locally" do
|
|
45
|
-
output = Whenever.cron \
|
|
46
|
-
<<-file
|
|
47
|
-
set :job_template, nil
|
|
48
|
-
job_type :some_job, "before :task after :option1"
|
|
49
|
-
set :option1, 'global'
|
|
50
|
-
every 2.hours do
|
|
51
|
-
some_job "during", :option1 => 'local'
|
|
52
|
-
end
|
|
53
|
-
file
|
|
54
|
-
|
|
55
|
-
assert_match(/^.+ .+ .+ .+ before during after local$/, output)
|
|
56
|
-
end
|
|
57
|
-
|
|
58
|
-
test "defined job with a :task and an option where the option is set globally and on the group" do
|
|
59
|
-
output = Whenever.cron \
|
|
60
|
-
<<-file
|
|
61
|
-
set :job_template, nil
|
|
62
|
-
job_type :some_job, "before :task after :option1"
|
|
63
|
-
set :option1, 'global'
|
|
64
|
-
every 2.hours, :option1 => 'group' do
|
|
65
|
-
some_job "during"
|
|
66
|
-
end
|
|
67
|
-
file
|
|
68
|
-
|
|
69
|
-
assert_match(/^.+ .+ .+ .+ before during after group$/, output)
|
|
70
|
-
end
|
|
71
|
-
|
|
72
|
-
test "defined job with a :task and an option where the option is set globally, on the group, and locally" do
|
|
73
|
-
output = Whenever.cron \
|
|
74
|
-
<<-file
|
|
75
|
-
set :job_template, nil
|
|
76
|
-
job_type :some_job, "before :task after :option1"
|
|
77
|
-
set :option1, 'global'
|
|
78
|
-
every 2.hours, :option1 => 'group' do
|
|
79
|
-
some_job "during", :option1 => 'local'
|
|
80
|
-
end
|
|
81
|
-
file
|
|
82
|
-
|
|
83
|
-
assert_match(/^.+ .+ .+ .+ before during after local$/, output)
|
|
84
|
-
end
|
|
85
|
-
|
|
86
|
-
test "defined job with a :task and an option that is not set" do
|
|
87
|
-
output = Whenever.cron \
|
|
88
|
-
<<-file
|
|
89
|
-
set :job_template, nil
|
|
90
|
-
job_type :some_job, "before :task after :option1"
|
|
91
|
-
every 2.hours do
|
|
92
|
-
some_job "during", :option2 => 'happy'
|
|
93
|
-
end
|
|
94
|
-
file
|
|
95
|
-
|
|
96
|
-
assert_match(/^.+ .+ .+ .+ before during after :option1$/, output)
|
|
97
|
-
end
|
|
98
|
-
|
|
99
|
-
test "defined job that uses a :path where none is explicitly set" do
|
|
100
|
-
Whenever.stubs(:path).returns('/my/path')
|
|
101
|
-
|
|
102
|
-
output = Whenever.cron \
|
|
103
|
-
<<-file
|
|
104
|
-
set :job_template, nil
|
|
105
|
-
job_type :some_job, "cd :path && :task"
|
|
106
|
-
every 2.hours do
|
|
107
|
-
some_job 'blahblah'
|
|
108
|
-
end
|
|
109
|
-
file
|
|
110
|
-
|
|
111
|
-
assert_match two_hours + %( cd /my/path && blahblah), output
|
|
112
|
-
end
|
|
113
|
-
end
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
require 'test_helper'
|
|
2
|
-
|
|
3
|
-
class OutputDescriptionTest < Whenever::TestCase
|
|
4
|
-
test "single line description" do
|
|
5
|
-
output = Whenever.cron \
|
|
6
|
-
<<-file
|
|
7
|
-
every "weekday", :description => "A description" do
|
|
8
|
-
command "blahblah"
|
|
9
|
-
end
|
|
10
|
-
file
|
|
11
|
-
|
|
12
|
-
assert_match "# A description\n0 0 * * 1-5 /bin/bash -l -c 'blahblah'\n\n", output
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
test "multi line description" do
|
|
16
|
-
output = Whenever.cron \
|
|
17
|
-
<<-file
|
|
18
|
-
every "weekday", :description => "A description\nhas mulitple lines" do
|
|
19
|
-
command "blahblah"
|
|
20
|
-
end
|
|
21
|
-
file
|
|
22
|
-
|
|
23
|
-
assert_match "# A description\n# has mulitple lines\n0 0 * * 1-5 /bin/bash -l -c 'blahblah'\n\n", output
|
|
24
|
-
end
|
|
25
|
-
end
|