super-clean-box 0.0.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.
- checksums.yaml +7 -0
- data/super-clean-box.gemspec +12 -0
- data/whenever-1.1.2/Appraisals +69 -0
- data/whenever-1.1.2/CHANGELOG.md +434 -0
- data/whenever-1.1.2/CONTRIBUTING.md +38 -0
- data/whenever-1.1.2/Gemfile +11 -0
- data/whenever-1.1.2/LICENSE +22 -0
- data/whenever-1.1.2/Makefile +5 -0
- data/whenever-1.1.2/README.md +350 -0
- data/whenever-1.1.2/Rakefile +10 -0
- data/whenever-1.1.2/bin/whenever +49 -0
- data/whenever-1.1.2/bin/wheneverize +71 -0
- data/whenever-1.1.2/gemfiles/activesupport5.0.gemfile +11 -0
- data/whenever-1.1.2/gemfiles/activesupport5.1.gemfile +11 -0
- data/whenever-1.1.2/gemfiles/activesupport5.2.gemfile +11 -0
- data/whenever-1.1.2/gemfiles/activesupport6.0.gemfile +17 -0
- data/whenever-1.1.2/gemfiles/activesupport6.1.gemfile +17 -0
- data/whenever-1.1.2/gemfiles/activesupport7.0.gemfile +11 -0
- data/whenever-1.1.2/gemfiles/activesupport7.1.gemfile +11 -0
- data/whenever-1.1.2/gemfiles/activesupport7.2.gemfile +11 -0
- data/whenever-1.1.2/gemfiles/activesupport8.0.gemfile +11 -0
- data/whenever-1.1.2/gemfiles/activesupport8.1.gemfile +11 -0
- data/whenever-1.1.2/lib/whenever/capistrano/v2/hooks.rb +8 -0
- data/whenever-1.1.2/lib/whenever/capistrano/v2/recipes.rb +49 -0
- data/whenever-1.1.2/lib/whenever/capistrano/v2/support.rb +53 -0
- data/whenever-1.1.2/lib/whenever/capistrano/v3/tasks/whenever.rake +56 -0
- data/whenever-1.1.2/lib/whenever/capistrano.rb +7 -0
- data/whenever-1.1.2/lib/whenever/command_line.rb +171 -0
- data/whenever-1.1.2/lib/whenever/cron.rb +181 -0
- data/whenever-1.1.2/lib/whenever/job.rb +56 -0
- data/whenever-1.1.2/lib/whenever/job_list.rb +186 -0
- data/whenever-1.1.2/lib/whenever/numeric.rb +13 -0
- data/whenever-1.1.2/lib/whenever/numeric_seconds.rb +48 -0
- data/whenever-1.1.2/lib/whenever/os.rb +7 -0
- data/whenever-1.1.2/lib/whenever/output_redirection.rb +57 -0
- data/whenever-1.1.2/lib/whenever/setup.rb +31 -0
- data/whenever-1.1.2/lib/whenever/version.rb +3 -0
- data/whenever-1.1.2/lib/whenever.rb +42 -0
- data/whenever-1.1.2/test/functional/command_line_test.rb +458 -0
- data/whenever-1.1.2/test/functional/output_at_test.rb +246 -0
- data/whenever-1.1.2/test/functional/output_default_defined_jobs_test.rb +310 -0
- data/whenever-1.1.2/test/functional/output_defined_job_test.rb +113 -0
- data/whenever-1.1.2/test/functional/output_description_test.rb +25 -0
- data/whenever-1.1.2/test/functional/output_env_test.rb +29 -0
- data/whenever-1.1.2/test/functional/output_jobs_for_roles_test.rb +65 -0
- data/whenever-1.1.2/test/functional/output_jobs_with_mailto_test.rb +168 -0
- data/whenever-1.1.2/test/functional/output_redirection_test.rb +248 -0
- data/whenever-1.1.2/test/test_case.rb +32 -0
- data/whenever-1.1.2/test/test_helper.rb +51 -0
- data/whenever-1.1.2/test/unit/capistrano_support_test.rb +147 -0
- data/whenever-1.1.2/test/unit/cron_test.rb +418 -0
- data/whenever-1.1.2/test/unit/executable_test.rb +142 -0
- data/whenever-1.1.2/test/unit/job_test.rb +114 -0
- data/whenever-1.1.2/whenever.gemspec +29 -0
- metadata +94 -0
|
@@ -0,0 +1,458 @@
|
|
|
1
|
+
require 'test_helper'
|
|
2
|
+
|
|
3
|
+
class CommandLineWriteTest < Whenever::TestCase
|
|
4
|
+
setup do
|
|
5
|
+
Time.stubs(:now).returns(Time.new(2017, 2, 24, 16, 21, 30, '+01:00'))
|
|
6
|
+
File.expects(:exist?).with('config/schedule.rb').returns(true)
|
|
7
|
+
@command = Whenever::CommandLine.new(:write => true, :identifier => 'My identifier')
|
|
8
|
+
@task = "#{two_hours} /my/command"
|
|
9
|
+
Whenever.expects(:cron).returns(@task)
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
should "output the cron job with identifier blocks" do
|
|
13
|
+
output = <<-EXPECTED
|
|
14
|
+
# Begin Whenever generated tasks for: My identifier at: 2017-02-24 16:21:30 +0100
|
|
15
|
+
#{@task}
|
|
16
|
+
# End Whenever generated tasks for: My identifier at: 2017-02-24 16:21:30 +0100
|
|
17
|
+
EXPECTED
|
|
18
|
+
|
|
19
|
+
assert_equal output, @command.send(:whenever_cron)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
should "write the crontab when run" do
|
|
23
|
+
@command.expects(:write_crontab).returns(true)
|
|
24
|
+
assert @command.run
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
class CommandLineUpdateTest < Whenever::TestCase
|
|
29
|
+
setup do
|
|
30
|
+
Time.stubs(:now).returns(Time.new(2017, 2, 24, 16, 21, 30, '+01:00'))
|
|
31
|
+
File.expects(:exist?).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 at: 2017-02-24 16:21:30 +0100
|
|
45
|
+
#{@task}
|
|
46
|
+
# End Whenever generated tasks for: My identifier at: 2017-02-24 16:21:30 +0100
|
|
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 and the timestamp doesn't" do
|
|
56
|
+
existing = <<-EXISTING_CRON
|
|
57
|
+
# Something
|
|
58
|
+
|
|
59
|
+
# Begin Whenever generated tasks for: My identifier at: 2017-01-03 08:02:22 +0500
|
|
60
|
+
My whenever job that was already here
|
|
61
|
+
# End Whenever generated tasks for: My identifier at: 2017-01-03 08:22:22 +0500
|
|
62
|
+
|
|
63
|
+
# Begin Whenever generated tasks for: Other identifier at: 2017-02-24 16:21:30 +0100
|
|
64
|
+
This shouldn't get replaced
|
|
65
|
+
# End Whenever generated tasks for: Other identifier at: 2017-02-24 16:21:30 +0100
|
|
66
|
+
EXISTING_CRON
|
|
67
|
+
|
|
68
|
+
new_cron = <<-NEW_CRON
|
|
69
|
+
# Something
|
|
70
|
+
|
|
71
|
+
# Begin Whenever generated tasks for: My identifier at: 2017-02-24 16:21:30 +0100
|
|
72
|
+
#{@task}
|
|
73
|
+
# End Whenever generated tasks for: My identifier at: 2017-02-24 16:21:30 +0100
|
|
74
|
+
|
|
75
|
+
# Begin Whenever generated tasks for: Other identifier at: 2017-02-24 16:21:30 +0100
|
|
76
|
+
This shouldn't get replaced
|
|
77
|
+
# End Whenever generated tasks for: Other identifier at: 2017-02-24 16:21:30 +0100
|
|
78
|
+
NEW_CRON
|
|
79
|
+
|
|
80
|
+
@command.expects(:read_crontab).at_least_once.returns(existing)
|
|
81
|
+
assert_equal new_cron, @command.send(:updated_crontab)
|
|
82
|
+
|
|
83
|
+
@command.expects(:write_crontab).with(new_cron).returns(true)
|
|
84
|
+
assert @command.run
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
should "replace an existing block if the identifier matches and the UTC timestamp doesn't" do
|
|
88
|
+
existing = <<-EXISTING_CRON
|
|
89
|
+
# Something
|
|
90
|
+
|
|
91
|
+
# Begin Whenever generated tasks for: My identifier at: 2017-01-03 08:02:22 UTC
|
|
92
|
+
My whenever job that was already here
|
|
93
|
+
# End Whenever generated tasks for: My identifier at: 2017-01-03 08:22:22 UTC
|
|
94
|
+
|
|
95
|
+
# Begin Whenever generated tasks for: Other identifier at: 2017-02-24 16:21:30 +0100
|
|
96
|
+
This shouldn't get replaced
|
|
97
|
+
# End Whenever generated tasks for: Other identifier at: 2017-02-24 16:21:30 +0100
|
|
98
|
+
EXISTING_CRON
|
|
99
|
+
|
|
100
|
+
new_cron = <<-NEW_CRON
|
|
101
|
+
# Something
|
|
102
|
+
|
|
103
|
+
# Begin Whenever generated tasks for: My identifier at: 2017-02-24 16:21:30 +0100
|
|
104
|
+
#{@task}
|
|
105
|
+
# End Whenever generated tasks for: My identifier at: 2017-02-24 16:21:30 +0100
|
|
106
|
+
|
|
107
|
+
# Begin Whenever generated tasks for: Other identifier at: 2017-02-24 16:21:30 +0100
|
|
108
|
+
This shouldn't get replaced
|
|
109
|
+
# End Whenever generated tasks for: Other identifier at: 2017-02-24 16:21:30 +0100
|
|
110
|
+
NEW_CRON
|
|
111
|
+
|
|
112
|
+
@command.expects(:read_crontab).at_least_once.returns(existing)
|
|
113
|
+
assert_equal new_cron, @command.send(:updated_crontab)
|
|
114
|
+
|
|
115
|
+
@command.expects(:write_crontab).with(new_cron).returns(true)
|
|
116
|
+
assert @command.run
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
should "replace an existing block if the identifier matches and it doesn't contain a timestamp" do
|
|
120
|
+
existing = <<-EXISTING_CRON
|
|
121
|
+
# Something
|
|
122
|
+
|
|
123
|
+
# Begin Whenever generated tasks for: My identifier
|
|
124
|
+
My whenever job that was already here
|
|
125
|
+
# End Whenever generated tasks for: My identifier
|
|
126
|
+
|
|
127
|
+
# Begin Whenever generated tasks for: Other identifier at: 2017-02-24 16:21:30 +0100
|
|
128
|
+
This shouldn't get replaced
|
|
129
|
+
# End Whenever generated tasks for: Other identifier at: 2017-02-24 16:21:30 +0100
|
|
130
|
+
EXISTING_CRON
|
|
131
|
+
|
|
132
|
+
new_cron = <<-NEW_CRON
|
|
133
|
+
# Something
|
|
134
|
+
|
|
135
|
+
# Begin Whenever generated tasks for: My identifier at: 2017-02-24 16:21:30 +0100
|
|
136
|
+
#{@task}
|
|
137
|
+
# End Whenever generated tasks for: My identifier at: 2017-02-24 16:21:30 +0100
|
|
138
|
+
|
|
139
|
+
# Begin Whenever generated tasks for: Other identifier at: 2017-02-24 16:21:30 +0100
|
|
140
|
+
This shouldn't get replaced
|
|
141
|
+
# End Whenever generated tasks for: Other identifier at: 2017-02-24 16:21:30 +0100
|
|
142
|
+
NEW_CRON
|
|
143
|
+
|
|
144
|
+
@command.expects(:read_crontab).at_least_once.returns(existing)
|
|
145
|
+
assert_equal new_cron, @command.send(:updated_crontab)
|
|
146
|
+
|
|
147
|
+
@command.expects(:write_crontab).with(new_cron).returns(true)
|
|
148
|
+
assert @command.run
|
|
149
|
+
end
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
class CommandLineUpdateWithBackslashesTest < Whenever::TestCase
|
|
153
|
+
setup do
|
|
154
|
+
Time.stubs(:now).returns(Time.new(2017, 2, 24, 16, 21, 30, '+01:00'))
|
|
155
|
+
@existing = <<-EXISTING_CRON
|
|
156
|
+
# Begin Whenever generated tasks for: My identifier at: 2017-02-24 16:21:30 +0100
|
|
157
|
+
script/runner -e production 'puts '\\''hello'\\'''
|
|
158
|
+
# End Whenever generated tasks for: My identifier at: 2017-02-24 16:21:30 +0100
|
|
159
|
+
EXISTING_CRON
|
|
160
|
+
File.expects(:exist?).with('config/schedule.rb').returns(true)
|
|
161
|
+
@command = Whenever::CommandLine.new(:update => true, :identifier => 'My identifier')
|
|
162
|
+
@command.expects(:read_crontab).at_least_once.returns(@existing)
|
|
163
|
+
@command.expects(:whenever_cron).returns(@existing)
|
|
164
|
+
end
|
|
165
|
+
|
|
166
|
+
should "replace the existing block with the backslashes in tact" do
|
|
167
|
+
assert_equal @existing, @command.send(:updated_crontab)
|
|
168
|
+
end
|
|
169
|
+
end
|
|
170
|
+
|
|
171
|
+
class CommandLineUpdateToSimilarCrontabTest < Whenever::TestCase
|
|
172
|
+
setup do
|
|
173
|
+
@existing = <<-EXISTING_CRON
|
|
174
|
+
# Begin Whenever generated tasks for: WheneverExisting at: 2017-02-24 16:21:30 +0100
|
|
175
|
+
# End Whenever generated tasks for: WheneverExisting at: 2017-02-24 16:21:30 +0100
|
|
176
|
+
EXISTING_CRON
|
|
177
|
+
@new = <<-NEW_CRON
|
|
178
|
+
# Begin Whenever generated tasks for: Whenever at: 2017-02-24 16:21:30 +0100
|
|
179
|
+
# End Whenever generated tasks for: Whenever at: 2017-02-24 16:21:30 +0100
|
|
180
|
+
NEW_CRON
|
|
181
|
+
File.expects(:exist?).with('config/schedule.rb').returns(true)
|
|
182
|
+
@command = Whenever::CommandLine.new(:update => true, :identifier => 'Whenever')
|
|
183
|
+
@command.expects(:read_crontab).at_least_once.returns(@existing)
|
|
184
|
+
@command.expects(:whenever_cron).returns(@new)
|
|
185
|
+
end
|
|
186
|
+
|
|
187
|
+
should "append the similarly named command" do
|
|
188
|
+
assert_equal @existing + "\n" + @new, @command.send(:updated_crontab)
|
|
189
|
+
end
|
|
190
|
+
end
|
|
191
|
+
|
|
192
|
+
class CommandLineClearTest < Whenever::TestCase
|
|
193
|
+
setup do
|
|
194
|
+
Time.stubs(:now).returns(Time.new(2017, 2, 24, 16, 21, 30, '+01:00'))
|
|
195
|
+
File.expects(:exist?).with('config/schedule.rb').returns(true)
|
|
196
|
+
@command = Whenever::CommandLine.new(:clear => true, :identifier => 'My identifier')
|
|
197
|
+
@task = "#{two_hours} /my/command"
|
|
198
|
+
end
|
|
199
|
+
|
|
200
|
+
should "clear an existing block if the identifier matches and the timestamp doesn't" do
|
|
201
|
+
existing = <<-EXISTING_CRON
|
|
202
|
+
# Something
|
|
203
|
+
|
|
204
|
+
# Begin Whenever generated tasks for: My identifier at: 2017-01-03 08:20:02 +0500
|
|
205
|
+
My whenever job that was already here
|
|
206
|
+
# End Whenever generated tasks for: My identifier at: 2017-01-03 08:20:02 +0500
|
|
207
|
+
|
|
208
|
+
# Begin Whenever generated tasks for: Other identifier at: 2017-02-24 16:21:30 +0100
|
|
209
|
+
This shouldn't get replaced
|
|
210
|
+
# End Whenever generated tasks for: Other identifier at: 2017-02-24 16:21:30 +0100
|
|
211
|
+
EXISTING_CRON
|
|
212
|
+
|
|
213
|
+
@command.expects(:read_crontab).at_least_once.returns(existing)
|
|
214
|
+
|
|
215
|
+
new_cron = <<-NEW_CRON
|
|
216
|
+
# Something
|
|
217
|
+
|
|
218
|
+
# Begin Whenever generated tasks for: Other identifier at: 2017-02-24 16:21:30 +0100
|
|
219
|
+
This shouldn't get replaced
|
|
220
|
+
# End Whenever generated tasks for: Other identifier at: 2017-02-24 16:21:30 +0100
|
|
221
|
+
NEW_CRON
|
|
222
|
+
|
|
223
|
+
assert_equal new_cron, @command.send(:updated_crontab)
|
|
224
|
+
|
|
225
|
+
@command.expects(:write_crontab).with(new_cron).returns(true)
|
|
226
|
+
assert @command.run
|
|
227
|
+
end
|
|
228
|
+
|
|
229
|
+
should "clear an existing block if the identifier matches and the UTC timestamp doesn't" do
|
|
230
|
+
existing = <<-EXISTING_CRON
|
|
231
|
+
# Something
|
|
232
|
+
|
|
233
|
+
# Begin Whenever generated tasks for: My identifier at: 2017-01-03 08:20:02 UTC
|
|
234
|
+
My whenever job that was already here
|
|
235
|
+
# End Whenever generated tasks for: My identifier at: 2017-01-03 08:20:02 UTC
|
|
236
|
+
|
|
237
|
+
# Begin Whenever generated tasks for: Other identifier at: 2017-02-24 16:21:30 +0100
|
|
238
|
+
This shouldn't get replaced
|
|
239
|
+
# End Whenever generated tasks for: Other identifier at: 2017-02-24 16:21:30 +0100
|
|
240
|
+
EXISTING_CRON
|
|
241
|
+
|
|
242
|
+
@command.expects(:read_crontab).at_least_once.returns(existing)
|
|
243
|
+
|
|
244
|
+
new_cron = <<-NEW_CRON
|
|
245
|
+
# Something
|
|
246
|
+
|
|
247
|
+
# Begin Whenever generated tasks for: Other identifier at: 2017-02-24 16:21:30 +0100
|
|
248
|
+
This shouldn't get replaced
|
|
249
|
+
# End Whenever generated tasks for: Other identifier at: 2017-02-24 16:21:30 +0100
|
|
250
|
+
NEW_CRON
|
|
251
|
+
|
|
252
|
+
assert_equal new_cron, @command.send(:updated_crontab)
|
|
253
|
+
|
|
254
|
+
@command.expects(:write_crontab).with(new_cron).returns(true)
|
|
255
|
+
assert @command.run
|
|
256
|
+
end
|
|
257
|
+
|
|
258
|
+
should "clear an existing block if the identifier matches and it doesn't have a timestamp" do
|
|
259
|
+
existing = <<-EXISTING_CRON
|
|
260
|
+
# Something
|
|
261
|
+
|
|
262
|
+
# Begin Whenever generated tasks for: My identifier
|
|
263
|
+
My whenever job that was already here
|
|
264
|
+
# End Whenever generated tasks for: My identifier
|
|
265
|
+
|
|
266
|
+
# Begin Whenever generated tasks for: Other identifier at: 2017-02-24 16:21:30 +0100
|
|
267
|
+
This shouldn't get replaced
|
|
268
|
+
# End Whenever generated tasks for: Other identifier at: 2017-02-24 16:21:30 +0100
|
|
269
|
+
EXISTING_CRON
|
|
270
|
+
|
|
271
|
+
@command.expects(:read_crontab).at_least_once.returns(existing)
|
|
272
|
+
|
|
273
|
+
new_cron = <<-NEW_CRON
|
|
274
|
+
# Something
|
|
275
|
+
|
|
276
|
+
# Begin Whenever generated tasks for: Other identifier at: 2017-02-24 16:21:30 +0100
|
|
277
|
+
This shouldn't get replaced
|
|
278
|
+
# End Whenever generated tasks for: Other identifier at: 2017-02-24 16:21:30 +0100
|
|
279
|
+
NEW_CRON
|
|
280
|
+
|
|
281
|
+
assert_equal new_cron, @command.send(:updated_crontab)
|
|
282
|
+
|
|
283
|
+
@command.expects(:write_crontab).with(new_cron).returns(true)
|
|
284
|
+
assert @command.run
|
|
285
|
+
end
|
|
286
|
+
end
|
|
287
|
+
|
|
288
|
+
class CommandLineClearWithNoScheduleTest < Whenever::TestCase
|
|
289
|
+
setup do
|
|
290
|
+
File.expects(:exist?).with('config/schedule.rb').returns(false)
|
|
291
|
+
@command = Whenever::CommandLine.new(:clear => true, :identifier => 'My identifier')
|
|
292
|
+
end
|
|
293
|
+
|
|
294
|
+
should "run successfully" do
|
|
295
|
+
@command.expects(:write_crontab).returns(true)
|
|
296
|
+
assert @command.run
|
|
297
|
+
end
|
|
298
|
+
end
|
|
299
|
+
|
|
300
|
+
class CommandLineUpdateWithNoIdentifierTest < Whenever::TestCase
|
|
301
|
+
setup do
|
|
302
|
+
Time.stubs(:now).returns(Time.new(2017, 2, 24, 16, 21, 30, '+01:00'))
|
|
303
|
+
File.expects(:exist?).with('config/schedule.rb').returns(true)
|
|
304
|
+
Whenever::CommandLine.any_instance.expects(:default_identifier).returns('DEFAULT')
|
|
305
|
+
@command = Whenever::CommandLine.new(:update => true)
|
|
306
|
+
end
|
|
307
|
+
|
|
308
|
+
should "use the default identifier" do
|
|
309
|
+
assert_equal "Whenever generated tasks for: DEFAULT at: 2017-02-24 16:21:30 +0100", @command.send(:comment_base)
|
|
310
|
+
end
|
|
311
|
+
end
|
|
312
|
+
|
|
313
|
+
class CombinedParamsTest < Whenever::TestCase
|
|
314
|
+
setup do
|
|
315
|
+
Whenever::CommandLine.any_instance.expects(:exit)
|
|
316
|
+
Whenever::CommandLine.any_instance.expects(:warn)
|
|
317
|
+
File.expects(:exist?).with('config/schedule.rb').returns(true)
|
|
318
|
+
end
|
|
319
|
+
|
|
320
|
+
should "exit with write and clear" do
|
|
321
|
+
@command = Whenever::CommandLine.new(:write => true, :clear => true)
|
|
322
|
+
end
|
|
323
|
+
|
|
324
|
+
should "exit with write and update" do
|
|
325
|
+
@command = Whenever::CommandLine.new(:write => true, :update => true)
|
|
326
|
+
end
|
|
327
|
+
|
|
328
|
+
should "exit with update and clear" do
|
|
329
|
+
@command = Whenever::CommandLine.new(:update => true, :clear => true)
|
|
330
|
+
end
|
|
331
|
+
end
|
|
332
|
+
|
|
333
|
+
class RunnerOverwrittenWithSetOptionTest < Whenever::TestCase
|
|
334
|
+
setup do
|
|
335
|
+
@output = Whenever.cron :set => 'environment=serious', :string => \
|
|
336
|
+
<<-file
|
|
337
|
+
set :job_template, nil
|
|
338
|
+
set :environment, :silly
|
|
339
|
+
set :path, '/my/path'
|
|
340
|
+
every 2.hours do
|
|
341
|
+
runner "blahblah"
|
|
342
|
+
end
|
|
343
|
+
file
|
|
344
|
+
end
|
|
345
|
+
|
|
346
|
+
should "output the runner using the override environment" do
|
|
347
|
+
assert_match two_hours + %( cd /my/path && bundle exec script/runner -e serious 'blahblah'), @output
|
|
348
|
+
end
|
|
349
|
+
end
|
|
350
|
+
|
|
351
|
+
|
|
352
|
+
class EnvironmentAndPathOverwrittenWithSetOptionTest < Whenever::TestCase
|
|
353
|
+
setup do
|
|
354
|
+
@output = Whenever.cron :set => 'environment=serious&path=/serious/path', :string => \
|
|
355
|
+
<<-file
|
|
356
|
+
set :job_template, nil
|
|
357
|
+
set :environment, :silly
|
|
358
|
+
set :path, '/silly/path'
|
|
359
|
+
every 2.hours do
|
|
360
|
+
runner "blahblah"
|
|
361
|
+
end
|
|
362
|
+
file
|
|
363
|
+
end
|
|
364
|
+
|
|
365
|
+
should "output the runner using the overridden path and environment" do
|
|
366
|
+
assert_match two_hours + %( cd /serious/path && bundle exec script/runner -e serious 'blahblah'), @output
|
|
367
|
+
end
|
|
368
|
+
end
|
|
369
|
+
|
|
370
|
+
class EnvironmentAndPathOverwrittenWithSetOptionWithSpacesTest < Whenever::TestCase
|
|
371
|
+
setup do
|
|
372
|
+
@output = Whenever.cron :set => ' environment = serious& path =/serious/path', :string => \
|
|
373
|
+
<<-file
|
|
374
|
+
set :job_template, nil
|
|
375
|
+
set :environment, :silly
|
|
376
|
+
set :path, '/silly/path'
|
|
377
|
+
every 2.hours do
|
|
378
|
+
runner "blahblah"
|
|
379
|
+
end
|
|
380
|
+
file
|
|
381
|
+
end
|
|
382
|
+
|
|
383
|
+
should "output the runner using the overridden path and environment" do
|
|
384
|
+
assert_match two_hours + %( cd /serious/path && bundle exec script/runner -e serious 'blahblah'), @output
|
|
385
|
+
end
|
|
386
|
+
end
|
|
387
|
+
|
|
388
|
+
class EnvironmentOverwrittenWithoutValueTest < Whenever::TestCase
|
|
389
|
+
setup do
|
|
390
|
+
@output = Whenever.cron :set => ' environment=', :string => \
|
|
391
|
+
<<-file
|
|
392
|
+
set :job_template, nil
|
|
393
|
+
set :environment, :silly
|
|
394
|
+
set :path, '/silly/path'
|
|
395
|
+
every 2.hours do
|
|
396
|
+
runner "blahblah"
|
|
397
|
+
end
|
|
398
|
+
file
|
|
399
|
+
end
|
|
400
|
+
|
|
401
|
+
should "output the runner using the original environment" do
|
|
402
|
+
assert_match two_hours + %( cd /silly/path && bundle exec script/runner -e silly 'blahblah'), @output
|
|
403
|
+
end
|
|
404
|
+
end
|
|
405
|
+
|
|
406
|
+
class PreparingOutputTest < Whenever::TestCase
|
|
407
|
+
setup do
|
|
408
|
+
File.expects(:exist?).with('config/schedule.rb').returns(true)
|
|
409
|
+
end
|
|
410
|
+
|
|
411
|
+
should "not trim off the top lines of the file" do
|
|
412
|
+
@command = Whenever::CommandLine.new(:update => true, :identifier => 'My identifier', :cut => 0)
|
|
413
|
+
existing = <<-EXISTING_CRON
|
|
414
|
+
# Useless Comments
|
|
415
|
+
# at the top of the file
|
|
416
|
+
|
|
417
|
+
# Begin Whenever generated tasks for: My identifier at: 2017-02-24 16:21:30 +0100
|
|
418
|
+
My whenever job that was already here
|
|
419
|
+
# End Whenever generated tasks for: My identifier at: 2017-02-24 16:21:30 +0100
|
|
420
|
+
EXISTING_CRON
|
|
421
|
+
|
|
422
|
+
assert_equal existing, @command.send(:prepare, existing)
|
|
423
|
+
end
|
|
424
|
+
|
|
425
|
+
should "trim off the top lines of the file" do
|
|
426
|
+
@command = Whenever::CommandLine.new(:update => true, :identifier => 'My identifier', :cut => '3')
|
|
427
|
+
existing = <<-EXISTING_CRON
|
|
428
|
+
# Useless Comments
|
|
429
|
+
# at the top of the file
|
|
430
|
+
|
|
431
|
+
# Begin Whenever generated tasks for: My identifier at: 2017-02-24 16:21:30 +0100
|
|
432
|
+
My whenever job that was already here
|
|
433
|
+
# End Whenever generated tasks for: My identifier at: 2017-02-24 16:21:30 +0100
|
|
434
|
+
EXISTING_CRON
|
|
435
|
+
|
|
436
|
+
new_cron = <<-NEW_CRON
|
|
437
|
+
# Begin Whenever generated tasks for: My identifier at: 2017-02-24 16:21:30 +0100
|
|
438
|
+
My whenever job that was already here
|
|
439
|
+
# End Whenever generated tasks for: My identifier at: 2017-02-24 16:21:30 +0100
|
|
440
|
+
NEW_CRON
|
|
441
|
+
|
|
442
|
+
assert_equal new_cron, @command.send(:prepare, existing)
|
|
443
|
+
end
|
|
444
|
+
|
|
445
|
+
should "preserve terminating newlines in files" do
|
|
446
|
+
@command = Whenever::CommandLine.new(:update => true, :identifier => 'My identifier')
|
|
447
|
+
existing = <<-EXISTING_CRON
|
|
448
|
+
# Begin Whenever generated tasks for: My identifier at: 2017-02-24 16:21:30 +0100
|
|
449
|
+
My whenever job that was already here
|
|
450
|
+
# End Whenever generated tasks for: My identifier at: 2017-02-24 16:21:30 +0100
|
|
451
|
+
|
|
452
|
+
# A non-Whenever task
|
|
453
|
+
My non-whenever job that was already here
|
|
454
|
+
EXISTING_CRON
|
|
455
|
+
|
|
456
|
+
assert_equal existing, @command.send(:prepare, existing)
|
|
457
|
+
end
|
|
458
|
+
end
|
|
@@ -0,0 +1,246 @@
|
|
|
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
|