whenever 0.9.2 → 0.10.0
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/.gitignore +1 -0
- data/.travis.yml +17 -7
- data/CHANGELOG.md +63 -0
- data/Gemfile +0 -5
- data/LICENSE +1 -1
- data/README.md +101 -18
- data/Rakefile +3 -10
- data/bin/whenever +3 -0
- data/bin/wheneverize +8 -5
- data/gemfiles/activesupport4.1.gemfile +5 -0
- data/gemfiles/activesupport4.2.gemfile +5 -0
- data/lib/whenever/capistrano/v2/recipes.rb +4 -3
- data/lib/whenever/capistrano/v3/tasks/whenever.rake +20 -7
- data/lib/whenever/capistrano.rb +1 -1
- data/lib/whenever/command_line.rb +49 -28
- data/lib/whenever/cron.rb +43 -21
- data/lib/whenever/job.rb +4 -3
- 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/setup.rb +5 -1
- data/lib/whenever/version.rb +1 -1
- data/lib/whenever.rb +15 -14
- data/test/functional/command_line_test.rb +379 -255
- data/test/functional/output_at_test.rb +227 -249
- data/test/functional/output_default_defined_jobs_test.rb +239 -288
- 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 -66
- data/test/functional/output_jobs_with_mailto_test.rb +168 -0
- data/test/functional/output_redirection_test.rb +231 -309
- data/test/test_case.rb +32 -0
- data/test/test_helper.rb +44 -15
- data/test/unit/capistrano_support_test.rb +126 -148
- data/test/unit/cron_test.rb +327 -210
- data/test/unit/executable_test.rb +142 -0
- data/test/unit/job_test.rb +111 -121
- data/whenever.gemspec +5 -4
- metadata +37 -28
- data/lib/whenever/tasks/whenever.rake +0 -43
data/test/unit/cron_test.rb
CHANGED
|
@@ -1,253 +1,370 @@
|
|
|
1
|
-
require
|
|
1
|
+
require 'test_helper'
|
|
2
2
|
|
|
3
|
-
class CronTest <
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
assert_raises ArgumentError do
|
|
8
|
-
parse_time(59.seconds)
|
|
9
|
-
end
|
|
10
|
-
|
|
11
|
-
assert_raises ArgumentError do
|
|
12
|
-
parse_time(0.minutes)
|
|
13
|
-
end
|
|
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))
|
|
14
7
|
end
|
|
15
8
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
assert_equal '* * * * *', parse_time(1.minute)
|
|
19
|
-
assert_equal '0,5,10,15,20,25,30,35,40,45,50,55 * * * *', parse_time(5.minutes)
|
|
20
|
-
assert_equal '7,14,21,28,35,42,49,56 * * * *', parse_time(7.minutes)
|
|
21
|
-
assert_equal '0,30 * * * *', parse_time(30.minutes)
|
|
22
|
-
assert_equal '32 * * * *', parse_time(32.minutes)
|
|
23
|
-
assert_not_equal '60 * * * *', parse_time(60.minutes) # 60 minutes bumps up into the hour range
|
|
9
|
+
assert_raises ArgumentError do
|
|
10
|
+
parse_time(Whenever.seconds(0, :minutes))
|
|
24
11
|
end
|
|
12
|
+
end
|
|
25
13
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
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
|
|
32
23
|
|
|
33
|
-
|
|
34
|
-
|
|
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))
|
|
35
32
|
end
|
|
36
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
|
|
37
45
|
|
|
38
|
-
|
|
39
|
-
should "parse correctly" do
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
assert_equal
|
|
45
|
-
assert_not_equal '0 24 * * *', parse_time(24.hours) # 24 hours bumps up into the day range
|
|
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))
|
|
46
53
|
end
|
|
54
|
+
end
|
|
47
55
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
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
|
|
53
62
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
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
|
|
57
70
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
end
|
|
72
|
-
end
|
|
73
|
-
|
|
74
|
-
context "When parsing time in days (of month)" do
|
|
75
|
-
should "parse correctly" do
|
|
76
|
-
assert_equal '0 0 * * *', parse_time(1.days)
|
|
77
|
-
assert_equal '0 0 1,3,5,7,9,11,13,15,17,19,21,23,25,27,29,31 * *', parse_time(2.days)
|
|
78
|
-
assert_equal '0 0 1,5,9,13,17,21,25,29 * *', parse_time(4.days)
|
|
79
|
-
assert_equal '0 0 1,8,15,22 * *', parse_time(7.days)
|
|
80
|
-
assert_equal '0 0 1,17 * *', parse_time(16.days)
|
|
81
|
-
assert_equal '0 0 17 * *', parse_time(17.days)
|
|
82
|
-
assert_equal '0 0 29 * *', parse_time(29.days)
|
|
83
|
-
assert_not_equal '0 0 30 * *', parse_time(30.days) # 30 days bumps into the month range
|
|
84
|
-
end
|
|
85
|
-
|
|
86
|
-
should "parse correctly when given an 'at' with hours, minutes as a Time" do
|
|
87
|
-
# first param is an array with [hours, minutes]
|
|
88
|
-
assert_hours_and_minutes_equals %w(3 45), '3:45am'
|
|
89
|
-
assert_hours_and_minutes_equals %w(20 1), '8:01pm'
|
|
90
|
-
assert_hours_and_minutes_equals %w(0 0), 'midnight'
|
|
91
|
-
assert_hours_and_minutes_equals %w(1 23), '1:23 AM'
|
|
92
|
-
assert_hours_and_minutes_equals %w(23 59), 'March 21 11:59 pM'
|
|
93
|
-
end
|
|
94
|
-
|
|
95
|
-
should "parse correctly when given an 'at' with hours as an Integer" do
|
|
96
|
-
# first param is an array with [hours, minutes]
|
|
97
|
-
assert_hours_and_minutes_equals %w(1 0), 1
|
|
98
|
-
assert_hours_and_minutes_equals %w(3 0), 3
|
|
99
|
-
assert_hours_and_minutes_equals %w(15 0), 15
|
|
100
|
-
assert_hours_and_minutes_equals %w(19 0), 19
|
|
101
|
-
assert_hours_and_minutes_equals %w(23 0), 23
|
|
102
|
-
end
|
|
103
|
-
end
|
|
104
|
-
|
|
105
|
-
context "When parsing time in months" do
|
|
106
|
-
should "parse correctly" do
|
|
107
|
-
assert_equal '0 0 1 * *', parse_time(1.month)
|
|
108
|
-
assert_equal '0 0 1 1,3,5,7,9,11 *', parse_time(2.months)
|
|
109
|
-
assert_equal '0 0 1 1,4,7,10 *', parse_time(3.months)
|
|
110
|
-
assert_equal '0 0 1 1,5,9 *', parse_time(4.months)
|
|
111
|
-
assert_equal '0 0 1 1,6 *', parse_time(5.months)
|
|
112
|
-
assert_equal '0 0 1 7 *', parse_time(7.months)
|
|
113
|
-
assert_equal '0 0 1 8 *', parse_time(8.months)
|
|
114
|
-
assert_equal '0 0 1 9 *', parse_time(9.months)
|
|
115
|
-
assert_equal '0 0 1 10 *', parse_time(10.months)
|
|
116
|
-
assert_equal '0 0 1 11 *', parse_time(11.months)
|
|
117
|
-
assert_equal '0 0 1 12 *', parse_time(12.months)
|
|
118
|
-
end
|
|
119
|
-
|
|
120
|
-
should "parse months with a date and/or time" do
|
|
121
|
-
# should set the day to 1 if no date is given
|
|
122
|
-
assert_equal '0 17 1 * *', parse_time(1.month, nil, "5pm")
|
|
123
|
-
# should use the date if one is given
|
|
124
|
-
assert_equal '0 2 23 * *', parse_time(1.month, nil, "February 23rd at 2am")
|
|
125
|
-
# should use an iteger as the day
|
|
126
|
-
assert_equal '0 0 5 * *', parse_time(1.month, nil, 5)
|
|
127
|
-
end
|
|
128
|
-
|
|
129
|
-
should "parse correctly when given an 'at' with days, hours, minutes as a Time" do
|
|
130
|
-
# first param is an array with [days, hours, minutes]
|
|
131
|
-
assert_days_and_hours_and_minutes_equals %w(1 3 45), 'January 1st 3:45am'
|
|
132
|
-
assert_days_and_hours_and_minutes_equals %w(11 23 0), 'Feb 11 11PM'
|
|
133
|
-
assert_days_and_hours_and_minutes_equals %w(22 1 1), 'march 22nd at 1:01 am'
|
|
134
|
-
assert_days_and_hours_and_minutes_equals %w(23 0 0), 'march 22nd at midnight' # looks like midnight means the next day
|
|
135
|
-
end
|
|
136
|
-
|
|
137
|
-
should "parse correctly when given an 'at' with days as an Integer" do
|
|
138
|
-
# first param is an array with [days, hours, minutes]
|
|
139
|
-
assert_days_and_hours_and_minutes_equals %w(1 0 0), 1
|
|
140
|
-
assert_days_and_hours_and_minutes_equals %w(15 0 0), 15
|
|
141
|
-
assert_days_and_hours_and_minutes_equals %w(29 0 0), 29
|
|
142
|
-
end
|
|
143
|
-
end
|
|
144
|
-
|
|
145
|
-
context "When parsing time in days (of week)" do
|
|
146
|
-
should "parse days of the week correctly" do
|
|
147
|
-
{
|
|
148
|
-
'0' => %w(sun Sunday SUNDAY SUN),
|
|
149
|
-
'1' => %w(mon Monday MONDAY MON),
|
|
150
|
-
'2' => %w(tue tues Tuesday TUESDAY TUE),
|
|
151
|
-
'3' => %w(wed Wednesday WEDNESDAY WED),
|
|
152
|
-
'4' => %w(thu thurs thur Thursday THURSDAY THU),
|
|
153
|
-
'5' => %w(fri Friday FRIDAY FRI),
|
|
154
|
-
'6' => %w(sat Saturday SATURDAY SAT)
|
|
155
|
-
}.each do |day, day_tests|
|
|
156
|
-
day_tests.each do |day_test|
|
|
157
|
-
assert_equal "0 0 * * #{day}", parse_time(day_test)
|
|
158
|
-
end
|
|
159
|
-
end
|
|
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 "raise an exception when given an 'at' with an invalid minute value" do
|
|
82
|
+
assert_raises ArgumentError do
|
|
83
|
+
parse_time(Whenever.seconds(1, :hour), nil, 60)
|
|
160
84
|
end
|
|
161
85
|
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
assert_equal '22 2 * * 1', parse_time('Monday', nil, "2:22am")
|
|
165
|
-
assert_equal '55 17 * * 4', parse_time('THU', nil, "5:55PM")
|
|
86
|
+
assert_raises ArgumentError do
|
|
87
|
+
parse_time(Whenever.seconds(1, :hour), nil, -1)
|
|
166
88
|
end
|
|
89
|
+
end
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
class CronParseDaysTest < Whenever::TestCase
|
|
93
|
+
should "parse correctly" do
|
|
94
|
+
assert_equal '0 0 * * *', parse_time(Whenever.seconds(1, :days))
|
|
95
|
+
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))
|
|
96
|
+
assert_equal '0 0 1,5,9,13,17,21,25,29 * *', parse_time(Whenever.seconds(4, :days))
|
|
97
|
+
assert_equal '0 0 1,8,15,22 * *', parse_time(Whenever.seconds(7, :days))
|
|
98
|
+
assert_equal '0 0 1,17 * *', parse_time(Whenever.seconds(16, :days))
|
|
99
|
+
assert_equal '0 0 17 * *', parse_time(Whenever.seconds(17, :days))
|
|
100
|
+
assert_equal '0 0 29 * *', parse_time(Whenever.seconds(29, :days))
|
|
101
|
+
assert '0 0 30 * *' != parse_time(Whenever.seconds(30, :days)) # 30 days bumps into the month range
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
should "parse correctly when given an 'at' with hours, minutes as a Time" do
|
|
105
|
+
# first param is an array with [hours, minutes]
|
|
106
|
+
assert_hours_and_minutes_equals %w(3 45), '3:45am'
|
|
107
|
+
assert_hours_and_minutes_equals %w(20 1), '8:01pm'
|
|
108
|
+
assert_hours_and_minutes_equals %w(0 0), 'midnight'
|
|
109
|
+
assert_hours_and_minutes_equals %w(1 23), '1:23 AM'
|
|
110
|
+
assert_hours_and_minutes_equals %w(23 59), 'March 21 11:59 pM'
|
|
111
|
+
end
|
|
167
112
|
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
113
|
+
should "parse correctly when given an 'at' with hours, minutes as a Time and custom Chronic options are set" do
|
|
114
|
+
# first param is an array with [hours, minutes]
|
|
115
|
+
assert_hours_and_minutes_equals %w(15 15), '3:15'
|
|
116
|
+
assert_hours_and_minutes_equals %w(3 15), '3:15', :chronic_options => { :hours24 => true }
|
|
117
|
+
assert_hours_and_minutes_equals %w(15 15), '3:15', :chronic_options => { :hours24 => false }
|
|
118
|
+
|
|
119
|
+
assert_hours_and_minutes_equals %w(6 30), '6:30'
|
|
120
|
+
assert_hours_and_minutes_equals %w(6 30), '6:30', :chronic_options => { :hours24 => true }
|
|
121
|
+
assert_hours_and_minutes_equals %w(6 30), '6:30', :chronic_options => { :hours24 => false }
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
should "parse correctly when given an 'at' with hours as an Integer" do
|
|
125
|
+
# first param is an array with [hours, minutes]
|
|
126
|
+
assert_hours_and_minutes_equals %w(1 0), 1
|
|
127
|
+
assert_hours_and_minutes_equals %w(3 0), 3
|
|
128
|
+
assert_hours_and_minutes_equals %w(15 0), 15
|
|
129
|
+
assert_hours_and_minutes_equals %w(19 0), 19
|
|
130
|
+
assert_hours_and_minutes_equals %w(23 0), 23
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
should "raise an exception when given an 'at' with an invalid hour value" do
|
|
134
|
+
assert_raises ArgumentError do
|
|
135
|
+
parse_time(Whenever.seconds(1, :day), nil, 24)
|
|
173
136
|
end
|
|
174
137
|
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
assert_equal '0 0 * * 6,0', parse_time('Weekends')
|
|
178
|
-
assert_equal '0 7 * * 6,0', parse_time('Weekends', nil, "7am")
|
|
179
|
-
assert_equal '2 18 * * 6,0', parse_time('Weekends', nil, "6:02PM")
|
|
138
|
+
assert_raises ArgumentError do
|
|
139
|
+
parse_time(Whenever.seconds(1, :day), nil, -1)
|
|
180
140
|
end
|
|
181
141
|
end
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
class CronParseMonthsTest < Whenever::TestCase
|
|
145
|
+
should "parse correctly" do
|
|
146
|
+
assert_equal '0 0 1 * *', parse_time(Whenever.seconds(1, :month))
|
|
147
|
+
assert_equal '0 0 1 1,3,5,7,9,11 *', parse_time(Whenever.seconds(2, :months))
|
|
148
|
+
assert_equal '0 0 1 1,4,7,10 *', parse_time(Whenever.seconds(3, :months))
|
|
149
|
+
assert_equal '0 0 1 1,5,9 *', parse_time(Whenever.seconds(4, :months))
|
|
150
|
+
assert_equal '0 0 1 1,6 *', parse_time(Whenever.seconds(5, :months))
|
|
151
|
+
assert_equal '0 0 1 7 *', parse_time(Whenever.seconds(7, :months))
|
|
152
|
+
assert_equal '0 0 1 8 *', parse_time(Whenever.seconds(8, :months))
|
|
153
|
+
assert_equal '0 0 1 9 *', parse_time(Whenever.seconds(9, :months))
|
|
154
|
+
assert_equal '0 0 1 10 *', parse_time(Whenever.seconds(10, :months))
|
|
155
|
+
assert_equal '0 0 1 11 *', parse_time(Whenever.seconds(11, :months))
|
|
156
|
+
assert_equal '0 0 1 12 *', parse_time(Whenever.seconds(12, :months))
|
|
157
|
+
end
|
|
158
|
+
|
|
159
|
+
should "parse months with a date and/or time" do
|
|
160
|
+
# should set the day to 1 if no date is given
|
|
161
|
+
assert_equal '0 17 1 * *', parse_time(Whenever.seconds(1, :month), nil, "5pm")
|
|
162
|
+
# should use the date if one is given
|
|
163
|
+
assert_equal '0 2 23 * *', parse_time(Whenever.seconds(1, :month), nil, "February 23rd at 2am")
|
|
164
|
+
# should use an iteger as the day
|
|
165
|
+
assert_equal '0 0 5 * *', parse_time(Whenever.seconds(1, :month), nil, 5)
|
|
166
|
+
end
|
|
167
|
+
|
|
168
|
+
should "parse correctly when given an 'at' with days, hours, minutes as a Time" do
|
|
169
|
+
# first param is an array with [days, hours, minutes]
|
|
170
|
+
assert_days_and_hours_and_minutes_equals %w(1 3 45), 'January 1st 3:45am'
|
|
171
|
+
assert_days_and_hours_and_minutes_equals %w(11 23 0), 'Feb 11 11PM'
|
|
172
|
+
assert_days_and_hours_and_minutes_equals %w(22 1 1), 'march 22nd at 1:01 am'
|
|
173
|
+
assert_days_and_hours_and_minutes_equals %w(23 0 0), 'march 22nd at midnight' # looks like midnight means the next day
|
|
174
|
+
end
|
|
175
|
+
|
|
176
|
+
should "parse correctly when given an 'at' with days, hours, minutes as a Time and custom Chronic options are set" do
|
|
177
|
+
# first param is an array with [days, hours, minutes]
|
|
178
|
+
assert_days_and_hours_and_minutes_equals %w(22 15 45), 'February 22nd 3:45'
|
|
179
|
+
assert_days_and_hours_and_minutes_equals %w(22 15 45), '02/22 3:45'
|
|
180
|
+
assert_days_and_hours_and_minutes_equals %w(22 3 45), 'February 22nd 3:45', :chronic_options => { :hours24 => true }
|
|
181
|
+
assert_days_and_hours_and_minutes_equals %w(22 15 45), 'February 22nd 3:45', :chronic_options => { :hours24 => false }
|
|
182
|
+
|
|
183
|
+
assert_days_and_hours_and_minutes_equals %w(3 8 15), '02/03 8:15'
|
|
184
|
+
assert_days_and_hours_and_minutes_equals %w(3 8 15), '02/03 8:15', :chronic_options => { :endian_precedence => :middle }
|
|
185
|
+
assert_days_and_hours_and_minutes_equals %w(2 8 15), '02/03 8:15', :chronic_options => { :endian_precedence => :little }
|
|
186
|
+
|
|
187
|
+
assert_days_and_hours_and_minutes_equals %w(4 4 50), '03/04 4:50', :chronic_options => { :endian_precedence => :middle, :hours24 => true }
|
|
188
|
+
assert_days_and_hours_and_minutes_equals %w(4 16 50), '03/04 4:50', :chronic_options => { :endian_precedence => :middle, :hours24 => false }
|
|
189
|
+
assert_days_and_hours_and_minutes_equals %w(3 4 50), '03/04 4:50', :chronic_options => { :endian_precedence => :little, :hours24 => true }
|
|
190
|
+
assert_days_and_hours_and_minutes_equals %w(3 16 50), '03/04 4:50', :chronic_options => { :endian_precedence => :little, :hours24 => false }
|
|
191
|
+
end
|
|
182
192
|
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
+
should "parse correctly when given an 'at' with days as an Integer" do
|
|
194
|
+
# first param is an array with [days, hours, minutes]
|
|
195
|
+
assert_days_and_hours_and_minutes_equals %w(1 0 0), 1
|
|
196
|
+
assert_days_and_hours_and_minutes_equals %w(15 0 0), 15
|
|
197
|
+
assert_days_and_hours_and_minutes_equals %w(29 0 0), 29
|
|
198
|
+
end
|
|
199
|
+
|
|
200
|
+
should "raise an exception when given an 'at' with an invalid day value" do
|
|
201
|
+
assert_raises ArgumentError do
|
|
202
|
+
parse_time(Whenever.seconds(1, :month), nil, 32)
|
|
193
203
|
end
|
|
194
204
|
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
assert_equal '0 0 * * *', parse_time(:day)
|
|
198
|
-
assert_equal '0 * * * *', parse_time(:hour)
|
|
199
|
-
assert_equal '0 0 1 12 *', parse_time(:year)
|
|
200
|
-
assert_equal '0 0 1,8,15,22 * *', parse_time(:week)
|
|
205
|
+
assert_raises ArgumentError do
|
|
206
|
+
parse_time(Whenever.seconds(1, :month), nil, -1)
|
|
201
207
|
end
|
|
208
|
+
end
|
|
209
|
+
end
|
|
202
210
|
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
211
|
+
class CronParseYearTest < Whenever::TestCase
|
|
212
|
+
should "parse correctly" do
|
|
213
|
+
assert_equal '0 0 1 1 *', parse_time(Whenever.seconds(1, :year))
|
|
214
|
+
end
|
|
207
215
|
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
216
|
+
should "parse year with a date and/or time" do
|
|
217
|
+
# should set the day and month to 1 if no date is given
|
|
218
|
+
assert_equal '0 17 1 1 *', parse_time(Whenever.seconds(1, :year), nil, "5pm")
|
|
219
|
+
# should use the date if one is given
|
|
220
|
+
assert_equal '0 2 23 2 *', parse_time(Whenever.seconds(1, :year), nil, "February 23rd at 2am")
|
|
221
|
+
# should use an iteger as the month
|
|
222
|
+
assert_equal '0 0 1 5 *', parse_time(Whenever.seconds(1, :year), nil, 5)
|
|
223
|
+
end
|
|
211
224
|
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
225
|
+
should "parse correctly when given an 'at' with days, hours, minutes as a Time" do
|
|
226
|
+
# first param is an array with [months, days, hours, minutes]
|
|
227
|
+
assert_months_and_days_and_hours_and_minutes_equals %w(1 1 3 45), 'January 1st 3:45am'
|
|
228
|
+
assert_months_and_days_and_hours_and_minutes_equals %w(2 11 23 0), 'Feb 11 11PM'
|
|
229
|
+
assert_months_and_days_and_hours_and_minutes_equals %w(3 22 1 1), 'march 22nd at 1:01 am'
|
|
230
|
+
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
|
|
216
231
|
end
|
|
217
232
|
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
233
|
+
should "parse correctly when given an 'at' with days, hours, minutes as a Time and custom Chronic options are set" do
|
|
234
|
+
# first param is an array with [months, days, hours, minutes]
|
|
235
|
+
assert_months_and_days_and_hours_and_minutes_equals %w(2 22 15 45), 'February 22nd 3:45'
|
|
236
|
+
assert_months_and_days_and_hours_and_minutes_equals %w(2 22 15 45), '02/22 3:45'
|
|
237
|
+
assert_months_and_days_and_hours_and_minutes_equals %w(2 22 3 45), 'February 22nd 3:45', :chronic_options => { :hours24 => true }
|
|
238
|
+
assert_months_and_days_and_hours_and_minutes_equals %w(2 22 15 45), 'February 22nd 3:45', :chronic_options => { :hours24 => false }
|
|
239
|
+
|
|
240
|
+
assert_months_and_days_and_hours_and_minutes_equals %w(2 3 8 15), '02/03 8:15'
|
|
241
|
+
assert_months_and_days_and_hours_and_minutes_equals %w(2 3 8 15), '02/03 8:15', :chronic_options => { :endian_precedence => :middle }
|
|
242
|
+
assert_months_and_days_and_hours_and_minutes_equals %w(3 2 8 15), '02/03 8:15', :chronic_options => { :endian_precedence => :little }
|
|
243
|
+
|
|
244
|
+
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 }
|
|
245
|
+
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 }
|
|
246
|
+
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 }
|
|
247
|
+
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 }
|
|
248
|
+
end
|
|
249
|
+
|
|
250
|
+
should "parse correctly when given an 'at' with month as an Integer" do
|
|
251
|
+
# first param is an array with [months, days, hours, minutes]
|
|
252
|
+
assert_months_and_days_and_hours_and_minutes_equals %w(1 1 0 0), 1
|
|
253
|
+
assert_months_and_days_and_hours_and_minutes_equals %w(5 1 0 0), 5
|
|
254
|
+
assert_months_and_days_and_hours_and_minutes_equals %w(12 1 0 0), 12
|
|
255
|
+
end
|
|
256
|
+
|
|
257
|
+
should "raise an exception when given an 'at' with an invalid month value" do
|
|
258
|
+
assert_raises ArgumentError do
|
|
259
|
+
parse_time(Whenever.seconds(1, :year), nil, 13)
|
|
260
|
+
end
|
|
261
|
+
|
|
262
|
+
assert_raises ArgumentError do
|
|
263
|
+
parse_time(Whenever.seconds(1, :year), nil, -1)
|
|
264
|
+
end
|
|
265
|
+
end
|
|
266
|
+
end
|
|
267
|
+
|
|
268
|
+
class CronParseDaysOfWeekTest < Whenever::TestCase
|
|
269
|
+
should "parse days of the week correctly" do
|
|
270
|
+
{
|
|
271
|
+
'0' => %w(sun Sunday SUNDAY SUN),
|
|
272
|
+
'1' => %w(mon Monday MONDAY MON),
|
|
273
|
+
'2' => %w(tue tues Tuesday TUESDAY TUE),
|
|
274
|
+
'3' => %w(wed Wednesday WEDNESDAY WED),
|
|
275
|
+
'4' => %w(thu thurs thur Thursday THURSDAY THU),
|
|
276
|
+
'5' => %w(fri Friday FRIDAY FRI),
|
|
277
|
+
'6' => %w(sat Saturday SATURDAY SAT)
|
|
278
|
+
}.each do |day, day_tests|
|
|
279
|
+
day_tests.each do |day_test|
|
|
280
|
+
assert_equal "0 0 * * #{day}", parse_time(day_test)
|
|
226
281
|
end
|
|
227
282
|
end
|
|
228
283
|
end
|
|
229
284
|
|
|
230
|
-
|
|
285
|
+
should "allow additional directives" do
|
|
286
|
+
assert_equal '30 13 * * 5', parse_time('friday', nil, "1:30 pm")
|
|
287
|
+
assert_equal '22 2 * * 1', parse_time('Monday', nil, "2:22am")
|
|
288
|
+
assert_equal '55 17 * * 4', parse_time('THU', nil, "5:55PM")
|
|
289
|
+
end
|
|
231
290
|
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
assert_equal
|
|
291
|
+
should "parse weekday correctly" do
|
|
292
|
+
assert_equal '0 0 * * 1-5', parse_time('weekday')
|
|
293
|
+
assert_equal '0 0 * * 1-5', parse_time('Weekdays')
|
|
294
|
+
assert_equal '0 1 * * 1-5', parse_time('Weekdays', nil, "1:00 am")
|
|
295
|
+
assert_equal '59 5 * * 1-5', parse_time('Weekdays', nil, "5:59 am")
|
|
236
296
|
end
|
|
237
297
|
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
assert_equal
|
|
298
|
+
should "parse weekend correctly" do
|
|
299
|
+
assert_equal '0 0 * * 6,0', parse_time('weekend')
|
|
300
|
+
assert_equal '0 0 * * 6,0', parse_time('Weekends')
|
|
301
|
+
assert_equal '0 7 * * 6,0', parse_time('Weekends', nil, "7am")
|
|
302
|
+
assert_equal '2 18 * * 6,0', parse_time('Weekends', nil, "6:02PM")
|
|
303
|
+
end
|
|
304
|
+
end
|
|
305
|
+
|
|
306
|
+
class CronParseShortcutsTest < Whenever::TestCase
|
|
307
|
+
should "parse a :symbol into the correct shortcut" do
|
|
308
|
+
assert_equal '@reboot', parse_time(:reboot)
|
|
309
|
+
assert_equal '@annually', parse_time(:annually)
|
|
310
|
+
assert_equal '@yearly', parse_time(:yearly)
|
|
311
|
+
assert_equal '@daily', parse_time(:daily)
|
|
312
|
+
assert_equal '@midnight', parse_time(:midnight)
|
|
313
|
+
assert_equal '@monthly', parse_time(:monthly)
|
|
314
|
+
assert_equal '@weekly', parse_time(:weekly)
|
|
315
|
+
assert_equal '@hourly', parse_time(:hourly)
|
|
242
316
|
end
|
|
243
317
|
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
assert_equal
|
|
318
|
+
should "convert time-based shortcuts to times" do
|
|
319
|
+
assert_equal '0 0 1 * *', parse_time(:month)
|
|
320
|
+
assert_equal '0 0 * * *', parse_time(:day)
|
|
321
|
+
assert_equal '0 * * * *', parse_time(:hour)
|
|
322
|
+
assert_equal '0 0 1 1 *', parse_time(:year)
|
|
323
|
+
assert_equal '0 0 1,8,15,22 * *', parse_time(:week)
|
|
324
|
+
end
|
|
325
|
+
|
|
326
|
+
should "raise an exception if a valid shortcut is given but also an :at" do
|
|
327
|
+
assert_raises ArgumentError do
|
|
328
|
+
parse_time(:hourly, nil, "1:00 am")
|
|
329
|
+
end
|
|
330
|
+
|
|
331
|
+
assert_raises ArgumentError do
|
|
332
|
+
parse_time(:reboot, nil, 5)
|
|
333
|
+
end
|
|
334
|
+
|
|
335
|
+
assert_raises ArgumentError do
|
|
336
|
+
parse_time(:daily, nil, '4:20pm')
|
|
337
|
+
end
|
|
247
338
|
end
|
|
339
|
+
end
|
|
248
340
|
|
|
249
|
-
|
|
250
|
-
|
|
341
|
+
class CronParseRubyTimeTest < Whenever::TestCase
|
|
342
|
+
should "process things like `1.day` correctly" do
|
|
343
|
+
assert_equal "0 0 * * *", parse_time(1.day)
|
|
251
344
|
end
|
|
345
|
+
end
|
|
252
346
|
|
|
253
|
-
|
|
347
|
+
class CronParseRawTest < Whenever::TestCase
|
|
348
|
+
should "raise if cron-syntax string is too long" do
|
|
349
|
+
assert_raises ArgumentError do
|
|
350
|
+
parse_time('* * * * * *')
|
|
351
|
+
end
|
|
352
|
+
end
|
|
353
|
+
|
|
354
|
+
should "raise if cron-syntax string is invalid" do
|
|
355
|
+
assert_raises ArgumentError do
|
|
356
|
+
parse_time('** * * * *')
|
|
357
|
+
end
|
|
358
|
+
end
|
|
359
|
+
|
|
360
|
+
should "return the same cron sytax" do
|
|
361
|
+
crons = ['0 0 27-31 * *', '* * * * *', '2/3 1,9,22 11-26 1-6 *', '*/5 6-23 * * *',
|
|
362
|
+
"*\t*\t*\t*\t*",
|
|
363
|
+
'7 17 * * FRI', '7 17 * * Mon-Fri', '30 12 * Jun *', '30 12 * Jun-Aug *',
|
|
364
|
+
'@reboot', '@yearly', '@annually', '@monthly', '@weekly',
|
|
365
|
+
'@daily', '@midnight', '@hourly']
|
|
366
|
+
crons.each do |cron|
|
|
367
|
+
assert_equal cron, parse_time(cron)
|
|
368
|
+
end
|
|
369
|
+
end
|
|
370
|
+
end
|