whenever 0.8.2 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +1 -0
- data/.travis.yml +20 -7
- data/Appraisals +19 -0
- data/CHANGELOG.md +116 -3
- data/Gemfile +3 -3
- data/LICENSE +2 -2
- data/README.md +133 -32
- data/Rakefile +3 -10
- data/bin/whenever +3 -0
- data/bin/wheneverize +8 -5
- data/gemfiles/activesupport4.1.gemfile +7 -0
- data/gemfiles/activesupport4.2.gemfile +7 -0
- data/gemfiles/activesupport5.0.gemfile +7 -0
- data/gemfiles/activesupport5.1.gemfile +7 -0
- data/gemfiles/activesupport5.2.gemfile +7 -0
- data/lib/whenever/capistrano/v2/hooks.rb +8 -0
- data/lib/whenever/capistrano/{recipes.rb → v2/recipes.rb} +7 -13
- data/lib/whenever/capistrano/{support.rb → v2/support.rb} +12 -0
- data/lib/whenever/capistrano/v3/tasks/whenever.rake +56 -0
- data/lib/whenever/capistrano.rb +5 -6
- data/lib/whenever/command_line.rb +69 -48
- data/lib/whenever/cron.rb +54 -25
- data/lib/whenever/job.rb +13 -14
- data/lib/whenever/job_list.rb +54 -24
- data/lib/whenever/numeric.rb +13 -0
- data/lib/whenever/numeric_seconds.rb +48 -0
- data/lib/whenever/os.rb +7 -0
- data/lib/whenever/output_redirection.rb +1 -0
- data/lib/whenever/setup.rb +19 -15
- data/lib/whenever/version.rb +2 -2
- data/lib/whenever.rb +19 -14
- data/test/functional/command_line_test.rb +379 -243
- data/test/functional/output_at_test.rb +227 -249
- data/test/functional/output_default_defined_jobs_test.rb +251 -193
- data/test/functional/output_defined_job_test.rb +65 -91
- data/test/functional/output_env_test.rb +22 -26
- data/test/functional/output_jobs_for_roles_test.rb +46 -65
- data/test/functional/output_jobs_with_mailto_test.rb +168 -0
- data/test/functional/output_redirection_test.rb +232 -291
- data/test/test_case.rb +32 -0
- data/test/test_helper.rb +44 -15
- data/test/unit/capistrano_support_test.rb +128 -134
- data/test/unit/cron_test.rb +373 -208
- data/test/unit/executable_test.rb +142 -0
- data/test/unit/job_test.rb +111 -117
- data/whenever.gemspec +7 -4
- metadata +63 -44
@@ -1,322 +1,458 @@
|
|
1
|
-
require
|
2
|
-
|
3
|
-
class
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
end
|
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
|
12
11
|
|
13
|
-
|
14
|
-
|
15
|
-
# Begin Whenever generated tasks for: My identifier
|
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
|
16
15
|
#{@task}
|
17
|
-
# End Whenever generated tasks for: My identifier
|
16
|
+
# End Whenever generated tasks for: My identifier at: 2017-02-24 16:21:30 +0100
|
18
17
|
EXPECTED
|
19
18
|
|
20
|
-
|
21
|
-
|
19
|
+
assert_equal output, @command.send(:whenever_cron)
|
20
|
+
end
|
22
21
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
end
|
22
|
+
should "write the crontab when run" do
|
23
|
+
@command.expects(:write_crontab).returns(true)
|
24
|
+
assert @command.run
|
27
25
|
end
|
26
|
+
end
|
28
27
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
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
36
|
|
37
|
-
|
38
|
-
|
39
|
-
|
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
40
|
|
41
|
-
|
41
|
+
new_cron = <<-EXPECTED
|
42
42
|
#{existing}
|
43
43
|
|
44
|
-
# Begin Whenever generated tasks for: My identifier
|
44
|
+
# Begin Whenever generated tasks for: My identifier at: 2017-02-24 16:21:30 +0100
|
45
45
|
#{@task}
|
46
|
-
# End Whenever generated tasks for: My identifier
|
46
|
+
# End Whenever generated tasks for: My identifier at: 2017-02-24 16:21:30 +0100
|
47
47
|
EXPECTED
|
48
48
|
|
49
|
-
|
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)
|
50
114
|
|
51
|
-
|
52
|
-
|
53
|
-
|
115
|
+
@command.expects(:write_crontab).with(new_cron).returns(true)
|
116
|
+
assert @command.run
|
117
|
+
end
|
54
118
|
|
55
|
-
|
56
|
-
|
119
|
+
should "replace an existing block if the identifier matches and it doesn't contain a timestamp" do
|
120
|
+
existing = <<-EXISTING_CRON
|
57
121
|
# Something
|
58
122
|
|
59
123
|
# Begin Whenever generated tasks for: My identifier
|
60
124
|
My whenever job that was already here
|
61
125
|
# End Whenever generated tasks for: My identifier
|
62
126
|
|
63
|
-
# Begin Whenever generated tasks for: Other identifier
|
127
|
+
# Begin Whenever generated tasks for: Other identifier at: 2017-02-24 16:21:30 +0100
|
64
128
|
This shouldn't get replaced
|
65
|
-
# End Whenever generated tasks for: Other identifier
|
129
|
+
# End Whenever generated tasks for: Other identifier at: 2017-02-24 16:21:30 +0100
|
66
130
|
EXISTING_CRON
|
67
131
|
|
68
|
-
|
132
|
+
new_cron = <<-NEW_CRON
|
69
133
|
# Something
|
70
134
|
|
71
|
-
# Begin Whenever generated tasks for: My identifier
|
135
|
+
# Begin Whenever generated tasks for: My identifier at: 2017-02-24 16:21:30 +0100
|
72
136
|
#{@task}
|
73
|
-
# End Whenever generated tasks for: My identifier
|
137
|
+
# End Whenever generated tasks for: My identifier at: 2017-02-24 16:21:30 +0100
|
74
138
|
|
75
|
-
# Begin Whenever generated tasks for: Other identifier
|
139
|
+
# Begin Whenever generated tasks for: Other identifier at: 2017-02-24 16:21:30 +0100
|
76
140
|
This shouldn't get replaced
|
77
|
-
# End Whenever generated tasks for: Other identifier
|
141
|
+
# End Whenever generated tasks for: Other identifier at: 2017-02-24 16:21:30 +0100
|
78
142
|
NEW_CRON
|
79
143
|
|
80
|
-
|
81
|
-
|
144
|
+
@command.expects(:read_crontab).at_least_once.returns(existing)
|
145
|
+
assert_equal new_cron, @command.send(:updated_crontab)
|
82
146
|
|
83
|
-
|
84
|
-
|
85
|
-
end
|
147
|
+
@command.expects(:write_crontab).with(new_cron).returns(true)
|
148
|
+
assert @command.run
|
86
149
|
end
|
150
|
+
end
|
87
151
|
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
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
|
92
157
|
script/runner -e production 'puts '\\''hello'\\'''
|
93
|
-
# End Whenever generated tasks for: My identifier
|
158
|
+
# End Whenever generated tasks for: My identifier at: 2017-02-24 16:21:30 +0100
|
94
159
|
EXISTING_CRON
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
# Begin Whenever generated tasks for: WheneverExisting
|
110
|
-
# End Whenever generated tasks for: WheneverExisting
|
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
|
111
176
|
EXISTING_CRON
|
112
|
-
|
113
|
-
# Begin Whenever generated tasks for: Whenever
|
114
|
-
# End Whenever generated tasks for: Whenever
|
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
|
115
180
|
NEW_CRON
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
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
|
136
260
|
# Something
|
137
261
|
|
138
262
|
# Begin Whenever generated tasks for: My identifier
|
139
263
|
My whenever job that was already here
|
140
264
|
# End Whenever generated tasks for: My identifier
|
141
265
|
|
142
|
-
# Begin Whenever generated tasks for: Other identifier
|
266
|
+
# Begin Whenever generated tasks for: Other identifier at: 2017-02-24 16:21:30 +0100
|
143
267
|
This shouldn't get replaced
|
144
|
-
# End Whenever generated tasks for: Other identifier
|
268
|
+
# End Whenever generated tasks for: Other identifier at: 2017-02-24 16:21:30 +0100
|
145
269
|
EXISTING_CRON
|
146
270
|
|
147
|
-
|
271
|
+
@command.expects(:read_crontab).at_least_once.returns(existing)
|
148
272
|
|
149
|
-
|
273
|
+
new_cron = <<-NEW_CRON
|
150
274
|
# Something
|
151
275
|
|
152
|
-
# Begin Whenever generated tasks for: Other identifier
|
276
|
+
# Begin Whenever generated tasks for: Other identifier at: 2017-02-24 16:21:30 +0100
|
153
277
|
This shouldn't get replaced
|
154
|
-
# End Whenever generated tasks for: Other identifier
|
278
|
+
# End Whenever generated tasks for: Other identifier at: 2017-02-24 16:21:30 +0100
|
155
279
|
NEW_CRON
|
156
280
|
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
end
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
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 environmnet" 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
|
276
414
|
# Useless Comments
|
277
415
|
# at the top of the file
|
278
416
|
|
279
|
-
# Begin Whenever generated tasks for: My identifier
|
417
|
+
# Begin Whenever generated tasks for: My identifier at: 2017-02-24 16:21:30 +0100
|
280
418
|
My whenever job that was already here
|
281
|
-
# End Whenever generated tasks for: My identifier
|
419
|
+
# End Whenever generated tasks for: My identifier at: 2017-02-24 16:21:30 +0100
|
282
420
|
EXISTING_CRON
|
283
421
|
|
284
|
-
|
285
|
-
|
422
|
+
assert_equal existing, @command.send(:prepare, existing)
|
423
|
+
end
|
286
424
|
|
287
|
-
|
288
|
-
|
289
|
-
|
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
|
290
428
|
# Useless Comments
|
291
429
|
# at the top of the file
|
292
430
|
|
293
|
-
# Begin Whenever generated tasks for: My identifier
|
431
|
+
# Begin Whenever generated tasks for: My identifier at: 2017-02-24 16:21:30 +0100
|
294
432
|
My whenever job that was already here
|
295
|
-
# End Whenever generated tasks for: My identifier
|
433
|
+
# End Whenever generated tasks for: My identifier at: 2017-02-24 16:21:30 +0100
|
296
434
|
EXISTING_CRON
|
297
435
|
|
298
|
-
|
299
|
-
# Begin Whenever generated tasks for: My identifier
|
436
|
+
new_cron = <<-NEW_CRON
|
437
|
+
# Begin Whenever generated tasks for: My identifier at: 2017-02-24 16:21:30 +0100
|
300
438
|
My whenever job that was already here
|
301
|
-
# End Whenever generated tasks for: My identifier
|
439
|
+
# End Whenever generated tasks for: My identifier at: 2017-02-24 16:21:30 +0100
|
302
440
|
NEW_CRON
|
303
441
|
|
304
|
-
|
305
|
-
|
442
|
+
assert_equal new_cron, @command.send(:prepare, existing)
|
443
|
+
end
|
306
444
|
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
# Begin Whenever generated tasks for: My identifier
|
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
|
311
449
|
My whenever job that was already here
|
312
|
-
# End Whenever generated tasks for: My identifier
|
450
|
+
# End Whenever generated tasks for: My identifier at: 2017-02-24 16:21:30 +0100
|
313
451
|
|
314
452
|
# A non-Whenever task
|
315
453
|
My non-whenever job that was already here
|
316
454
|
EXISTING_CRON
|
317
455
|
|
318
|
-
|
319
|
-
end
|
456
|
+
assert_equal existing, @command.send(:prepare, existing)
|
320
457
|
end
|
321
|
-
|
322
458
|
end
|