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.
Files changed (55) hide show
  1. checksums.yaml +7 -0
  2. data/super-clean-box.gemspec +12 -0
  3. data/whenever-1.1.2/Appraisals +69 -0
  4. data/whenever-1.1.2/CHANGELOG.md +434 -0
  5. data/whenever-1.1.2/CONTRIBUTING.md +38 -0
  6. data/whenever-1.1.2/Gemfile +11 -0
  7. data/whenever-1.1.2/LICENSE +22 -0
  8. data/whenever-1.1.2/Makefile +5 -0
  9. data/whenever-1.1.2/README.md +350 -0
  10. data/whenever-1.1.2/Rakefile +10 -0
  11. data/whenever-1.1.2/bin/whenever +49 -0
  12. data/whenever-1.1.2/bin/wheneverize +71 -0
  13. data/whenever-1.1.2/gemfiles/activesupport5.0.gemfile +11 -0
  14. data/whenever-1.1.2/gemfiles/activesupport5.1.gemfile +11 -0
  15. data/whenever-1.1.2/gemfiles/activesupport5.2.gemfile +11 -0
  16. data/whenever-1.1.2/gemfiles/activesupport6.0.gemfile +17 -0
  17. data/whenever-1.1.2/gemfiles/activesupport6.1.gemfile +17 -0
  18. data/whenever-1.1.2/gemfiles/activesupport7.0.gemfile +11 -0
  19. data/whenever-1.1.2/gemfiles/activesupport7.1.gemfile +11 -0
  20. data/whenever-1.1.2/gemfiles/activesupport7.2.gemfile +11 -0
  21. data/whenever-1.1.2/gemfiles/activesupport8.0.gemfile +11 -0
  22. data/whenever-1.1.2/gemfiles/activesupport8.1.gemfile +11 -0
  23. data/whenever-1.1.2/lib/whenever/capistrano/v2/hooks.rb +8 -0
  24. data/whenever-1.1.2/lib/whenever/capistrano/v2/recipes.rb +49 -0
  25. data/whenever-1.1.2/lib/whenever/capistrano/v2/support.rb +53 -0
  26. data/whenever-1.1.2/lib/whenever/capistrano/v3/tasks/whenever.rake +56 -0
  27. data/whenever-1.1.2/lib/whenever/capistrano.rb +7 -0
  28. data/whenever-1.1.2/lib/whenever/command_line.rb +171 -0
  29. data/whenever-1.1.2/lib/whenever/cron.rb +181 -0
  30. data/whenever-1.1.2/lib/whenever/job.rb +56 -0
  31. data/whenever-1.1.2/lib/whenever/job_list.rb +186 -0
  32. data/whenever-1.1.2/lib/whenever/numeric.rb +13 -0
  33. data/whenever-1.1.2/lib/whenever/numeric_seconds.rb +48 -0
  34. data/whenever-1.1.2/lib/whenever/os.rb +7 -0
  35. data/whenever-1.1.2/lib/whenever/output_redirection.rb +57 -0
  36. data/whenever-1.1.2/lib/whenever/setup.rb +31 -0
  37. data/whenever-1.1.2/lib/whenever/version.rb +3 -0
  38. data/whenever-1.1.2/lib/whenever.rb +42 -0
  39. data/whenever-1.1.2/test/functional/command_line_test.rb +458 -0
  40. data/whenever-1.1.2/test/functional/output_at_test.rb +246 -0
  41. data/whenever-1.1.2/test/functional/output_default_defined_jobs_test.rb +310 -0
  42. data/whenever-1.1.2/test/functional/output_defined_job_test.rb +113 -0
  43. data/whenever-1.1.2/test/functional/output_description_test.rb +25 -0
  44. data/whenever-1.1.2/test/functional/output_env_test.rb +29 -0
  45. data/whenever-1.1.2/test/functional/output_jobs_for_roles_test.rb +65 -0
  46. data/whenever-1.1.2/test/functional/output_jobs_with_mailto_test.rb +168 -0
  47. data/whenever-1.1.2/test/functional/output_redirection_test.rb +248 -0
  48. data/whenever-1.1.2/test/test_case.rb +32 -0
  49. data/whenever-1.1.2/test/test_helper.rb +51 -0
  50. data/whenever-1.1.2/test/unit/capistrano_support_test.rb +147 -0
  51. data/whenever-1.1.2/test/unit/cron_test.rb +418 -0
  52. data/whenever-1.1.2/test/unit/executable_test.rb +142 -0
  53. data/whenever-1.1.2/test/unit/job_test.rb +114 -0
  54. data/whenever-1.1.2/whenever.gemspec +29 -0
  55. metadata +94 -0
@@ -0,0 +1,418 @@
1
+ require 'test_helper'
2
+
3
+ class CronTest < Whenever::TestCase
4
+ should "raise if less than 1 minute" do
5
+ assert_raises ArgumentError do
6
+ parse_time(Whenever.seconds(59, :seconds))
7
+ end
8
+
9
+ assert_raises ArgumentError do
10
+ parse_time(Whenever.seconds(0, :minutes))
11
+ end
12
+ end
13
+
14
+ # For sanity, do some tests on straight cron-syntax strings
15
+ should "parse correctly" do
16
+ assert_equal '* * * * *', parse_time(Whenever.seconds(1, :minute))
17
+ assert_equal '0,5,10,15,20,25,30,35,40,45,50,55 * * * *', parse_time(Whenever.seconds(5, :minutes))
18
+ assert_equal '7,14,21,28,35,42,49,56 * * * *', parse_time(Whenever.seconds(7, :minutes))
19
+ assert_equal '0,30 * * * *', parse_time(Whenever.seconds(30, :minutes))
20
+ assert_equal '32 * * * *', parse_time(Whenever.seconds(32, :minutes))
21
+ assert '60 * * * *' != parse_time(Whenever.seconds(60, :minutes)) # 60 minutes bumps up into the hour range
22
+ end
23
+
24
+ # Test all minutes
25
+ (2..59).each do |num|
26
+ should "parse correctly for #{num} minutes" do
27
+ start = 0
28
+ start += num unless 60.modulo(num).zero?
29
+ minutes = (start..59).step(num).to_a
30
+
31
+ assert_equal "#{minutes.join(',')} * * * *", parse_time(Whenever.seconds(num, :minutes))
32
+ end
33
+ end
34
+ end
35
+
36
+ class CronParseHoursTest < Whenever::TestCase
37
+ should "parse correctly" do
38
+ assert_equal '0 * * * *', parse_time(Whenever.seconds(1, :hour))
39
+ assert_equal '0 0,2,4,6,8,10,12,14,16,18,20,22 * * *', parse_time(Whenever.seconds(2, :hours))
40
+ assert_equal '0 0,3,6,9,12,15,18,21 * * *', parse_time(Whenever.seconds(3, :hours))
41
+ assert_equal '0 5,10,15,20 * * *', parse_time(Whenever.seconds(5, :hours))
42
+ assert_equal '0 17 * * *', parse_time(Whenever.seconds(17, :hours))
43
+ assert '0 24 * * *' != parse_time(Whenever.seconds(24, :hours)) # 24 hours bumps up into the day range
44
+ end
45
+
46
+ (2..23).each do |num|
47
+ should "parse correctly for #{num} hours" do
48
+ start = 0
49
+ start += num unless 24.modulo(num).zero?
50
+ hours = (start..23).step(num).to_a
51
+
52
+ assert_equal "0 #{hours.join(',')} * * *", parse_time(Whenever.seconds(num, :hours))
53
+ end
54
+ end
55
+
56
+ should "parse correctly when given an 'at' with minutes as an Integer" do
57
+ assert_minutes_equals "1", 1
58
+ assert_minutes_equals "14", 14
59
+ assert_minutes_equals "27", 27
60
+ assert_minutes_equals "55", 55
61
+ end
62
+
63
+ should "parse correctly when given an 'at' with minutes as a Time" do
64
+ # Basically just testing that Chronic parses some times and we get the minutes out of it
65
+ assert_minutes_equals "1", '3:01am'
66
+ assert_minutes_equals "1", 'January 21 2:01 PM'
67
+ assert_minutes_equals "0", 'midnight'
68
+ assert_minutes_equals "59", '13:59'
69
+ end
70
+
71
+ should "parse correctly when given an 'at' with minutes as a Time and custom Chronic options are set" do
72
+ assert_minutes_equals "15", '3:15'
73
+ assert_minutes_equals "15", '3:15', :chronic_options => { :hours24 => true }
74
+ assert_minutes_equals "15", '3:15', :chronic_options => { :hours24 => false }
75
+
76
+ assert_minutes_equals "30", '6:30'
77
+ assert_minutes_equals "30", '6:30', :chronic_options => { :hours24 => true }
78
+ assert_minutes_equals "30", '6:30', :chronic_options => { :hours24 => false }
79
+ end
80
+
81
+ should "parse correctly when given an 'at' with minutes as a Range" do
82
+ assert_minutes_equals "15-30", 15..30
83
+ end
84
+
85
+ should "raise an exception when given an 'at' with an invalid minute value" do
86
+ assert_raises ArgumentError do
87
+ parse_time(Whenever.seconds(1, :hour), nil, 60)
88
+ end
89
+
90
+ assert_raises ArgumentError do
91
+ parse_time(Whenever.seconds(1, :hour), nil, -1)
92
+ end
93
+
94
+ assert_raises ArgumentError do
95
+ parse_time(Whenever.seconds(1, :hour), nil, 0..60)
96
+ end
97
+
98
+ assert_raises ArgumentError do
99
+ parse_time(Whenever.seconds(1, :hour), nil, -1..59)
100
+ end
101
+ end
102
+ end
103
+
104
+ class CronParseDaysTest < Whenever::TestCase
105
+ should "parse correctly" do
106
+ assert_equal '0 0 * * *', parse_time(Whenever.seconds(1, :days))
107
+ assert_equal '0 0 1,3,5,7,9,11,13,15,17,19,21,23,25,27,29,31 * *', parse_time(Whenever.seconds(2, :days))
108
+ assert_equal '0 0 1,5,9,13,17,21,25,29 * *', parse_time(Whenever.seconds(4, :days))
109
+ assert_equal '0 0 1,8,15,22 * *', parse_time(Whenever.seconds(7, :days))
110
+ assert_equal '0 0 1,17 * *', parse_time(Whenever.seconds(16, :days))
111
+ assert_equal '0 0 17 * *', parse_time(Whenever.seconds(17, :days))
112
+ assert_equal '0 0 29 * *', parse_time(Whenever.seconds(29, :days))
113
+ assert '0 0 30 * *' != parse_time(Whenever.seconds(30, :days)) # 30 days bumps into the month range
114
+ end
115
+
116
+ should "parse correctly when given an 'at' with hours, minutes as a Time" do
117
+ # first param is an array with [hours, minutes]
118
+ assert_hours_and_minutes_equals %w(3 45), '3:45am'
119
+ assert_hours_and_minutes_equals %w(20 1), '8:01pm'
120
+ assert_hours_and_minutes_equals %w(0 0), 'midnight'
121
+ assert_hours_and_minutes_equals %w(1 23), '1:23 AM'
122
+ assert_hours_and_minutes_equals %w(23 59), 'March 21 11:59 pM'
123
+ end
124
+
125
+ should "parse correctly when given an 'at' with hours, minutes as a Time and custom Chronic options are set" do
126
+ # first param is an array with [hours, minutes]
127
+ assert_hours_and_minutes_equals %w(15 15), '3:15'
128
+ assert_hours_and_minutes_equals %w(3 15), '3:15', :chronic_options => { :hours24 => true }
129
+ assert_hours_and_minutes_equals %w(15 15), '3:15', :chronic_options => { :hours24 => false }
130
+
131
+ assert_hours_and_minutes_equals %w(6 30), '6:30'
132
+ assert_hours_and_minutes_equals %w(6 30), '6:30', :chronic_options => { :hours24 => true }
133
+ assert_hours_and_minutes_equals %w(6 30), '6:30', :chronic_options => { :hours24 => false }
134
+ end
135
+
136
+ should "parse correctly when given an 'at' with hours as an Integer" do
137
+ # first param is an array with [hours, minutes]
138
+ assert_hours_and_minutes_equals %w(1 0), 1
139
+ assert_hours_and_minutes_equals %w(3 0), 3
140
+ assert_hours_and_minutes_equals %w(15 0), 15
141
+ assert_hours_and_minutes_equals %w(19 0), 19
142
+ assert_hours_and_minutes_equals %w(23 0), 23
143
+ end
144
+
145
+ should "parse correctly when given an 'at' with hours as a Range" do
146
+ assert_hours_and_minutes_equals %w(3-23 0), 3..23
147
+ end
148
+
149
+ should "raise an exception when given an 'at' with an invalid hour value" do
150
+ assert_raises ArgumentError do
151
+ parse_time(Whenever.seconds(1, :day), nil, 24)
152
+ end
153
+
154
+ assert_raises ArgumentError do
155
+ parse_time(Whenever.seconds(1, :day), nil, -1)
156
+ end
157
+
158
+ assert_raises ArgumentError do
159
+ parse_time(Whenever.seconds(1, :day), nil, 0..24)
160
+ end
161
+
162
+ assert_raises ArgumentError do
163
+ parse_time(Whenever.seconds(1, :day), nil, -1..23)
164
+ end
165
+ end
166
+ end
167
+
168
+ class CronParseMonthsTest < Whenever::TestCase
169
+ should "parse correctly" do
170
+ assert_equal '0 0 1 * *', parse_time(Whenever.seconds(1, :month))
171
+ assert_equal '0 0 1 1,3,5,7,9,11 *', parse_time(Whenever.seconds(2, :months))
172
+ assert_equal '0 0 1 1,4,7,10 *', parse_time(Whenever.seconds(3, :months))
173
+ assert_equal '0 0 1 1,5,9 *', parse_time(Whenever.seconds(4, :months))
174
+ assert_equal '0 0 1 1,6 *', parse_time(Whenever.seconds(5, :months))
175
+ assert_equal '0 0 1 7 *', parse_time(Whenever.seconds(7, :months))
176
+ assert_equal '0 0 1 8 *', parse_time(Whenever.seconds(8, :months))
177
+ assert_equal '0 0 1 9 *', parse_time(Whenever.seconds(9, :months))
178
+ assert_equal '0 0 1 10 *', parse_time(Whenever.seconds(10, :months))
179
+ assert_equal '0 0 1 11 *', parse_time(Whenever.seconds(11, :months))
180
+ assert_equal '0 0 1 12 *', parse_time(Whenever.seconds(12, :months))
181
+ end
182
+
183
+ should "parse months with a date and/or time" do
184
+ # should set the day to 1 if no date is given
185
+ assert_equal '0 17 1 * *', parse_time(Whenever.seconds(1, :month), nil, "5pm")
186
+ # should use the date if one is given
187
+ assert_equal '0 2 23 * *', parse_time(Whenever.seconds(1, :month), nil, "February 23rd at 2am")
188
+ # should use an iteger as the day
189
+ assert_equal '0 0 5 * *', parse_time(Whenever.seconds(1, :month), nil, 5)
190
+ end
191
+
192
+ should "parse correctly when given an 'at' with days, hours, minutes as a Time" do
193
+ # first param is an array with [days, hours, minutes]
194
+ assert_days_and_hours_and_minutes_equals %w(1 3 45), 'January 1st 3:45am'
195
+ assert_days_and_hours_and_minutes_equals %w(11 23 0), 'Feb 11 11PM'
196
+ assert_days_and_hours_and_minutes_equals %w(22 1 1), 'march 22nd at 1:01 am'
197
+ assert_days_and_hours_and_minutes_equals %w(23 0 0), 'march 22nd at midnight' # looks like midnight means the next day
198
+ end
199
+
200
+ should "parse correctly when given an 'at' with days, hours, minutes as a Time and custom Chronic options are set" do
201
+ # first param is an array with [days, hours, minutes]
202
+ assert_days_and_hours_and_minutes_equals %w(22 15 45), 'February 22nd 3:45'
203
+ assert_days_and_hours_and_minutes_equals %w(22 15 45), '02/22 3:45'
204
+ assert_days_and_hours_and_minutes_equals %w(22 3 45), 'February 22nd 3:45', :chronic_options => { :hours24 => true }
205
+ assert_days_and_hours_and_minutes_equals %w(22 15 45), 'February 22nd 3:45', :chronic_options => { :hours24 => false }
206
+
207
+ assert_days_and_hours_and_minutes_equals %w(3 8 15), '02/03 8:15'
208
+ assert_days_and_hours_and_minutes_equals %w(3 8 15), '02/03 8:15', :chronic_options => { :endian_precedence => :middle }
209
+ assert_days_and_hours_and_minutes_equals %w(2 8 15), '02/03 8:15', :chronic_options => { :endian_precedence => :little }
210
+
211
+ assert_days_and_hours_and_minutes_equals %w(4 4 50), '03/04 4:50', :chronic_options => { :endian_precedence => :middle, :hours24 => true }
212
+ assert_days_and_hours_and_minutes_equals %w(4 16 50), '03/04 4:50', :chronic_options => { :endian_precedence => :middle, :hours24 => false }
213
+ assert_days_and_hours_and_minutes_equals %w(3 4 50), '03/04 4:50', :chronic_options => { :endian_precedence => :little, :hours24 => true }
214
+ assert_days_and_hours_and_minutes_equals %w(3 16 50), '03/04 4:50', :chronic_options => { :endian_precedence => :little, :hours24 => false }
215
+ end
216
+
217
+ should "parse correctly when given an 'at' with days as an Integer" do
218
+ # first param is an array with [days, hours, minutes]
219
+ assert_days_and_hours_and_minutes_equals %w(1 0 0), 1
220
+ assert_days_and_hours_and_minutes_equals %w(15 0 0), 15
221
+ assert_days_and_hours_and_minutes_equals %w(29 0 0), 29
222
+ end
223
+
224
+ should "parse correctly when given an 'at' with days as a Range" do
225
+ assert_days_and_hours_and_minutes_equals %w(1-7 0 0), 1..7
226
+ end
227
+
228
+ should "raise an exception when given an 'at' with an invalid day value" do
229
+ assert_raises ArgumentError do
230
+ parse_time(Whenever.seconds(1, :month), nil, 32)
231
+ end
232
+
233
+ assert_raises ArgumentError do
234
+ parse_time(Whenever.seconds(1, :month), nil, -1)
235
+ end
236
+
237
+ assert_raises ArgumentError do
238
+ parse_time(Whenever.seconds(1, :month), nil, 0..30)
239
+ end
240
+
241
+ assert_raises ArgumentError do
242
+ parse_time(Whenever.seconds(1, :month), nil, 1..32)
243
+ end
244
+ end
245
+ end
246
+
247
+ class CronParseYearTest < Whenever::TestCase
248
+ should "parse correctly" do
249
+ assert_equal '0 0 1 1 *', parse_time(Whenever.seconds(1, :year))
250
+ end
251
+
252
+ should "parse year with a date and/or time" do
253
+ # should set the day and month to 1 if no date is given
254
+ assert_equal '0 17 1 1 *', parse_time(Whenever.seconds(1, :year), nil, "5pm")
255
+ # should use the date if one is given
256
+ assert_equal '0 2 23 2 *', parse_time(Whenever.seconds(1, :year), nil, "February 23rd at 2am")
257
+ # should use an iteger as the month
258
+ assert_equal '0 0 1 5 *', parse_time(Whenever.seconds(1, :year), nil, 5)
259
+ end
260
+
261
+ should "parse correctly when given an 'at' with days, hours, minutes as a Time" do
262
+ # first param is an array with [months, days, hours, minutes]
263
+ assert_months_and_days_and_hours_and_minutes_equals %w(1 1 3 45), 'January 1st 3:45am'
264
+ assert_months_and_days_and_hours_and_minutes_equals %w(2 11 23 0), 'Feb 11 11PM'
265
+ assert_months_and_days_and_hours_and_minutes_equals %w(3 22 1 1), 'march 22nd at 1:01 am'
266
+ assert_months_and_days_and_hours_and_minutes_equals %w(3 23 0 0), 'march 22nd at midnight' # looks like midnight means the next day
267
+ end
268
+
269
+ should "parse correctly when given an 'at' with days, hours, minutes as a Time and custom Chronic options are set" do
270
+ # first param is an array with [months, days, hours, minutes]
271
+ assert_months_and_days_and_hours_and_minutes_equals %w(2 22 15 45), 'February 22nd 3:45'
272
+ assert_months_and_days_and_hours_and_minutes_equals %w(2 22 15 45), '02/22 3:45'
273
+ assert_months_and_days_and_hours_and_minutes_equals %w(2 22 3 45), 'February 22nd 3:45', :chronic_options => { :hours24 => true }
274
+ assert_months_and_days_and_hours_and_minutes_equals %w(2 22 15 45), 'February 22nd 3:45', :chronic_options => { :hours24 => false }
275
+
276
+ assert_months_and_days_and_hours_and_minutes_equals %w(2 3 8 15), '02/03 8:15'
277
+ assert_months_and_days_and_hours_and_minutes_equals %w(2 3 8 15), '02/03 8:15', :chronic_options => { :endian_precedence => :middle }
278
+ assert_months_and_days_and_hours_and_minutes_equals %w(3 2 8 15), '02/03 8:15', :chronic_options => { :endian_precedence => :little }
279
+
280
+ assert_months_and_days_and_hours_and_minutes_equals %w(3 4 4 50), '03/04 4:50', :chronic_options => { :endian_precedence => :middle, :hours24 => true }
281
+ assert_months_and_days_and_hours_and_minutes_equals %w(3 4 16 50), '03/04 4:50', :chronic_options => { :endian_precedence => :middle, :hours24 => false }
282
+ assert_months_and_days_and_hours_and_minutes_equals %w(4 3 4 50), '03/04 4:50', :chronic_options => { :endian_precedence => :little, :hours24 => true }
283
+ assert_months_and_days_and_hours_and_minutes_equals %w(4 3 16 50), '03/04 4:50', :chronic_options => { :endian_precedence => :little, :hours24 => false }
284
+ end
285
+
286
+ should "parse correctly when given an 'at' with month as an Integer" do
287
+ # first param is an array with [months, days, hours, minutes]
288
+ assert_months_and_days_and_hours_and_minutes_equals %w(1 1 0 0), 1
289
+ assert_months_and_days_and_hours_and_minutes_equals %w(5 1 0 0), 5
290
+ assert_months_and_days_and_hours_and_minutes_equals %w(12 1 0 0), 12
291
+ end
292
+
293
+ should "parse correctly when given an 'at' with month as a Range" do
294
+ assert_months_and_days_and_hours_and_minutes_equals %w(1-3 1 0 0), 1..3
295
+ end
296
+
297
+ should "raise an exception when given an 'at' with an invalid month value" do
298
+ assert_raises ArgumentError do
299
+ parse_time(Whenever.seconds(1, :year), nil, 13)
300
+ end
301
+
302
+ assert_raises ArgumentError do
303
+ parse_time(Whenever.seconds(1, :year), nil, -1)
304
+ end
305
+
306
+ assert_raises ArgumentError do
307
+ parse_time(Whenever.seconds(1, :year), nil, 0..12)
308
+ end
309
+
310
+ assert_raises ArgumentError do
311
+ parse_time(Whenever.seconds(1, :year), nil, 1..13)
312
+ end
313
+ end
314
+ end
315
+
316
+ class CronParseDaysOfWeekTest < Whenever::TestCase
317
+ should "parse days of the week correctly" do
318
+ {
319
+ '0' => %w(sun Sunday SUNDAY SUN),
320
+ '1' => %w(mon Monday MONDAY MON),
321
+ '2' => %w(tue tues Tuesday TUESDAY TUE),
322
+ '3' => %w(wed Wednesday WEDNESDAY WED),
323
+ '4' => %w(thu thurs thur Thursday THURSDAY THU),
324
+ '5' => %w(fri Friday FRIDAY FRI),
325
+ '6' => %w(sat Saturday SATURDAY SAT)
326
+ }.each do |day, day_tests|
327
+ day_tests.each do |day_test|
328
+ assert_equal "0 0 * * #{day}", parse_time(day_test)
329
+ end
330
+ end
331
+ end
332
+
333
+ should "allow additional directives" do
334
+ assert_equal '30 13 * * 5', parse_time('friday', nil, "1:30 pm")
335
+ assert_equal '22 2 * * 1', parse_time('Monday', nil, "2:22am")
336
+ assert_equal '55 17 * * 4', parse_time('THU', nil, "5:55PM")
337
+ end
338
+
339
+ should "parse weekday correctly" do
340
+ assert_equal '0 0 * * 1-5', parse_time('weekday')
341
+ assert_equal '0 0 * * 1-5', parse_time('Weekdays')
342
+ assert_equal '0 1 * * 1-5', parse_time('Weekdays', nil, "1:00 am")
343
+ assert_equal '59 5 * * 1-5', parse_time('Weekdays', nil, "5:59 am")
344
+ end
345
+
346
+ should "parse weekend correctly" do
347
+ assert_equal '0 0 * * 6,0', parse_time('weekend')
348
+ assert_equal '0 0 * * 6,0', parse_time('Weekends')
349
+ assert_equal '0 7 * * 6,0', parse_time('Weekends', nil, "7am")
350
+ assert_equal '2 18 * * 6,0', parse_time('Weekends', nil, "6:02PM")
351
+ end
352
+ end
353
+
354
+ class CronParseShortcutsTest < Whenever::TestCase
355
+ should "parse a :symbol into the correct shortcut" do
356
+ assert_equal '@reboot', parse_time(:reboot)
357
+ assert_equal '@annually', parse_time(:annually)
358
+ assert_equal '@yearly', parse_time(:yearly)
359
+ assert_equal '@daily', parse_time(:daily)
360
+ assert_equal '@midnight', parse_time(:midnight)
361
+ assert_equal '@monthly', parse_time(:monthly)
362
+ assert_equal '@weekly', parse_time(:weekly)
363
+ assert_equal '@hourly', parse_time(:hourly)
364
+ end
365
+
366
+ should "convert time-based shortcuts to times" do
367
+ assert_equal '0 0 1 * *', parse_time(:month)
368
+ assert_equal '0 0 * * *', parse_time(:day)
369
+ assert_equal '0 * * * *', parse_time(:hour)
370
+ assert_equal '0 0 1 1 *', parse_time(:year)
371
+ assert_equal '0 0 1,8,15,22 * *', parse_time(:week)
372
+ end
373
+
374
+ should "raise an exception if a valid shortcut is given but also an :at" do
375
+ assert_raises ArgumentError do
376
+ parse_time(:hourly, nil, "1:00 am")
377
+ end
378
+
379
+ assert_raises ArgumentError do
380
+ parse_time(:reboot, nil, 5)
381
+ end
382
+
383
+ assert_raises ArgumentError do
384
+ parse_time(:daily, nil, '4:20pm')
385
+ end
386
+ end
387
+ end
388
+
389
+ class CronParseRubyTimeTest < Whenever::TestCase
390
+ should "process things like `1.day` correctly" do
391
+ assert_equal "0 0 * * *", parse_time(1.day)
392
+ end
393
+ end
394
+
395
+ class CronParseRawTest < Whenever::TestCase
396
+ should "raise if cron-syntax string is too long" do
397
+ assert_raises ArgumentError do
398
+ parse_time('* * * * * *')
399
+ end
400
+ end
401
+
402
+ should "raise if cron-syntax string is invalid" do
403
+ assert_raises ArgumentError do
404
+ parse_time('** * * * *')
405
+ end
406
+ end
407
+
408
+ should "return the same cron sytax" do
409
+ crons = ['0 0 27-31 * *', '* * * * *', '2/3 1,9,22 11-26 1-6 *', '*/5 6-23 * * *',
410
+ "*\t*\t*\t*\t*",
411
+ '7 17 * * FRI', '7 17 * * Mon-Fri', '30 12 * Jun *', '30 12 * Jun-Aug *',
412
+ '@reboot', '@yearly', '@annually', '@monthly', '@weekly',
413
+ '@daily', '@midnight', '@hourly']
414
+ crons.each do |cron|
415
+ assert_equal cron, parse_time(cron)
416
+ end
417
+ end
418
+ end
@@ -0,0 +1,142 @@
1
+ require 'test_helper'
2
+
3
+ describe 'Executable' do
4
+ describe 'bin/wheneverize' do
5
+ describe 'ARGV is not empty' do
6
+ describe 'file does not exist' do
7
+ file = '/tmp/this_does_not_exist'
8
+
9
+ it 'prints STDERR' do
10
+ out, err = capture_subprocess_io do
11
+ system('wheneverize', file)
12
+ end
13
+
14
+ assert_empty(out)
15
+ assert_match(/`#{file}' does not exist./, err)
16
+ end
17
+ end
18
+
19
+ describe 'file exists, but not a directory' do
20
+ file = '/tmp/this_is_a_file.txt'
21
+ before { FileUtils.touch(file) }
22
+
23
+ it 'prints STDERR' do
24
+ begin
25
+ out, err = capture_subprocess_io do
26
+ system('wheneverize', file)
27
+ end
28
+
29
+ assert_empty(out)
30
+ assert_match(/`#{file}' is not a directory./, err)
31
+ ensure
32
+ FileUtils.rm(file)
33
+ end
34
+ end
35
+ end
36
+
37
+ describe 'file is a directory, but another param(s) are given as well' do
38
+ file = '/tmp/this_is_a_directory'
39
+ before { FileUtils.mkdir(file) }
40
+
41
+ it 'prints STDERR' do
42
+ begin
43
+ out, err = capture_subprocess_io do
44
+ system('wheneverize', file, 'another', 'parameters')
45
+ end
46
+
47
+ assert_empty(out)
48
+ assert_match(/#{"Too many arguments; please specify only the " \
49
+ "directory to wheneverize."}/, err)
50
+ ensure
51
+ FileUtils.rmdir(file)
52
+ end
53
+ end
54
+ end
55
+ end
56
+
57
+ describe 'ARGV is empty' do
58
+ dir = '.'
59
+ file = 'config/schedule.rb'
60
+ path = File.join(dir, file)
61
+
62
+ describe 'config file already exists' do
63
+ before do
64
+ FileUtils.mkdir(File.dirname(path))
65
+ FileUtils.touch(path)
66
+ end
67
+
68
+ it 'prints STDOUT and STDERR' do
69
+ begin
70
+ out, err = capture_subprocess_io do
71
+ system('wheneverize')
72
+ end
73
+
74
+ assert_match(/\[done\] wheneverized!/, out)
75
+ assert_match(/\[skip\] `#{path}' already exists/, err)
76
+ ensure
77
+ FileUtils.rm_rf(File.dirname(path))
78
+ end
79
+ end
80
+ end
81
+
82
+ describe 'config directory does not exist' do
83
+ it 'prints STDOUT and STDERR' do
84
+ begin
85
+ out, err = capture_subprocess_io do
86
+ system('wheneverize')
87
+ end
88
+
89
+ assert_match(/\[add\] creating `#{File.dirname(path)}'\n/, err)
90
+ assert_match(/\[done\] wheneverized!/, out)
91
+ ensure
92
+ FileUtils.rm_rf(File.dirname(path))
93
+ end
94
+ end
95
+ end
96
+
97
+ describe 'config directory exists, but file does not' do
98
+ before { FileUtils.mkdir(File.dirname(path)) }
99
+
100
+ it 'writes config file and prints STDOUT' do
101
+ begin
102
+ out, err = capture_subprocess_io do
103
+ system('wheneverize')
104
+ end
105
+
106
+ assert_empty(err)
107
+ assert_match(
108
+ /\[add\] writing `#{path}'\n\[done\] wheneverized!/,
109
+ out
110
+ )
111
+
112
+ assert_match((<<-FILE
113
+ # Use this file to easily define all of your cron jobs.
114
+ #
115
+ # It's helpful, but not entirely necessary to understand cron before proceeding.
116
+ # http://en.wikipedia.org/wiki/Cron
117
+
118
+ # Example:
119
+ #
120
+ # set :output, "/path/to/my/cron_log.log"
121
+ #
122
+ # every 2.hours do
123
+ # command "/usr/bin/some_great_command"
124
+ # runner "MyModel.some_method"
125
+ # rake "some:great:rake:task"
126
+ # end
127
+ #
128
+ # every 4.days do
129
+ # runner "AnotherModel.prune_old_records"
130
+ # end
131
+
132
+ # Learn more: http://github.com/javan/whenever
133
+ FILE
134
+ ), IO.read(path))
135
+ ensure
136
+ FileUtils.rm_rf(File.dirname(path))
137
+ end
138
+ end
139
+ end
140
+ end
141
+ end
142
+ end
@@ -0,0 +1,114 @@
1
+ require 'test_helper'
2
+
3
+ class JobTest < Whenever::TestCase
4
+ should "return the :at set when #at is called" do
5
+ assert_equal 'foo', new_job(:at => 'foo').at
6
+ end
7
+
8
+ should "return the :roles set when #roles is called" do
9
+ assert_equal ['foo', 'bar'], new_job(:roles => ['foo', 'bar']).roles
10
+ end
11
+
12
+ should "return whether it has a role from #has_role?" do
13
+ assert new_job(:roles => 'foo').has_role?('foo')
14
+ assert_equal false, new_job(:roles => 'bar').has_role?('foo')
15
+ end
16
+
17
+ should "substitute the :task when #output is called" do
18
+ job = new_job(:template => ":task", :task => 'abc123')
19
+ assert_equal 'abc123', job.output
20
+ end
21
+
22
+ should "substitute the :path when #output is called" do
23
+ assert_equal 'foo', new_job(:template => ':path', :path => 'foo').output
24
+ end
25
+
26
+ should "substitute the :path with the default Whenever.path if none is provided when #output is called" do
27
+ Whenever.expects(:path).returns('/my/path')
28
+ assert_equal '/my/path', new_job(:template => ':path').output
29
+ end
30
+
31
+ should "not substitute parameters for which no value is set" do
32
+ assert_equal 'Hello :world', new_job(:template => ':matching :world', :matching => 'Hello').output
33
+ end
34
+
35
+ should "escape the :path" do
36
+ assert_equal '/my/spacey\ path', new_job(:template => ':path', :path => '/my/spacey path').output
37
+ end
38
+
39
+ should "escape percent signs" do
40
+ job = new_job(
41
+ :template => "before :foo after",
42
+ :foo => "percent -> % <- percent"
43
+ )
44
+ assert_equal %q(before percent -> \% <- percent after), job.output
45
+ end
46
+
47
+ should "assume percent signs are not already escaped" do
48
+ job = new_job(
49
+ :template => "before :foo after",
50
+ :foo => %q(percent preceded by a backslash -> \% <-)
51
+ )
52
+ assert_equal %q(before percent preceded by a backslash -> \\\% <- after), job.output
53
+ end
54
+
55
+ should "squish spaces and newlines" do
56
+ job = new_job(
57
+ :template => "before :foo after",
58
+ :foo => "newline -> \n <- newline space -> <- space"
59
+ )
60
+
61
+ assert_equal "before newline -> <- newline space -> <- space after", job.output
62
+ end
63
+ end
64
+
65
+
66
+ class JobWithQuotesTest < Whenever::TestCase
67
+ should "output the :task if it's in single quotes" do
68
+ job = new_job(:template => "':task'", :task => 'abc123')
69
+ assert_equal %q('abc123'), job.output
70
+ end
71
+
72
+ should "output the :task if it's in double quotes" do
73
+ job = new_job(:template => '":task"', :task => 'abc123')
74
+ assert_equal %q("abc123"), job.output
75
+ end
76
+
77
+ should "output escaped single quotes in when it's wrapped in them" do
78
+ job = new_job(
79
+ :template => "before ':foo' after",
80
+ :foo => "quote -> ' <- quote"
81
+ )
82
+ assert_equal %q(before 'quote -> '\'' <- quote' after), job.output
83
+ end
84
+
85
+ should "output escaped double quotes when it's wrapped in them" do
86
+ job = new_job(
87
+ :template => 'before ":foo" after',
88
+ :foo => 'quote -> " <- quote'
89
+ )
90
+ assert_equal %q(before "quote -> \" <- quote" after), job.output
91
+ end
92
+ end
93
+
94
+ class JobWithJobTemplateTest < Whenever::TestCase
95
+ should "use the job template" do
96
+ job = new_job(:template => ':task', :task => 'abc123', :job_template => 'left :job right')
97
+ assert_equal 'left abc123 right', job.output
98
+ end
99
+
100
+ should "reuse parameter in the job template" do
101
+ job = new_job(:template => ':path :task', :path => 'path', :task => "abc123", :job_template => ':path left :job right')
102
+ assert_equal 'path left path abc123 right', job.output
103
+ end
104
+
105
+ should "escape single quotes" do
106
+ job = new_job(:template => "before ':task' after", :task => "quote -> ' <- quote", :job_template => "left ':job' right")
107
+ assert_equal %q(left 'before '\''quote -> '\\''\\'\\'''\\'' <- quote'\'' after' right), job.output
108
+ end
109
+
110
+ should "escape double quotes" do
111
+ job = new_job(:template => 'before ":task" after', :task => 'quote -> " <- quote', :job_template => 'left ":job" right')
112
+ assert_equal %q(left "before \"quote -> \\\" <- quote\" after" right), job.output
113
+ end
114
+ end