whenever 0.9.7 → 0.10.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +8 -5
- data/CHANGELOG.md +14 -0
- data/LICENSE +1 -1
- data/README.md +75 -10
- data/bin/whenever +3 -0
- data/bin/wheneverize +5 -2
- data/lib/whenever/capistrano/v2/recipes.rb +3 -2
- data/lib/whenever/capistrano/v3/tasks/whenever.rake +17 -4
- data/lib/whenever/command_line.rb +38 -18
- data/lib/whenever/cron.rb +32 -11
- data/lib/whenever/job.rb +2 -1
- data/lib/whenever/job_list.rb +50 -20
- data/lib/whenever/setup.rb +4 -0
- data/lib/whenever/version.rb +1 -1
- data/test/functional/command_line_test.rb +159 -32
- data/test/functional/output_at_test.rb +39 -0
- data/test/functional/output_jobs_with_mailto_test.rb +168 -0
- data/test/test_helper.rb +18 -8
- data/test/unit/cron_test.rb +130 -4
- data/test/unit/executable_test.rb +142 -0
- metadata +6 -2
@@ -204,4 +204,43 @@ class OutputAtTest < Whenever::TestCase
|
|
204
204
|
|
205
205
|
assert_match '0 0 27,31 * * blahblah', output
|
206
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
|
207
246
|
end
|
@@ -0,0 +1,168 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
class OutputJobsWithMailtoTest < Whenever::TestCase
|
4
|
+
test "defined job with a mailto argument" do
|
5
|
+
output = Whenever.cron \
|
6
|
+
<<-file
|
7
|
+
every 2.hours do
|
8
|
+
command "blahblah", mailto: 'someone@example.com'
|
9
|
+
end
|
10
|
+
file
|
11
|
+
|
12
|
+
output_without_empty_line = lines_without_empty_line(output.lines)
|
13
|
+
|
14
|
+
assert_equal 'MAILTO=someone@example.com', output_without_empty_line.shift
|
15
|
+
assert_equal two_hours + " /bin/bash -l -c 'blahblah'", output_without_empty_line.shift
|
16
|
+
end
|
17
|
+
|
18
|
+
test "defined job with every method's block and a mailto argument" do
|
19
|
+
output = Whenever.cron \
|
20
|
+
<<-file
|
21
|
+
every 2.hours, mailto: 'someone@example.com' do
|
22
|
+
command "blahblah"
|
23
|
+
end
|
24
|
+
file
|
25
|
+
|
26
|
+
output_without_empty_line = lines_without_empty_line(output.lines)
|
27
|
+
|
28
|
+
assert_equal 'MAILTO=someone@example.com', output_without_empty_line.shift
|
29
|
+
assert_equal two_hours + " /bin/bash -l -c 'blahblah'", output_without_empty_line.shift
|
30
|
+
end
|
31
|
+
|
32
|
+
test "defined job which overrided mailto argument in the block" do
|
33
|
+
output = Whenever.cron \
|
34
|
+
<<-file
|
35
|
+
every 2.hours, mailto: 'of_the_block@example.com' do
|
36
|
+
command "blahblah", mailto: 'overrided_in_the_block@example.com'
|
37
|
+
end
|
38
|
+
file
|
39
|
+
|
40
|
+
output_without_empty_line = lines_without_empty_line(output.lines)
|
41
|
+
|
42
|
+
assert_equal 'MAILTO=overrided_in_the_block@example.com', output_without_empty_line.shift
|
43
|
+
assert_equal two_hours + " /bin/bash -l -c 'blahblah'", output_without_empty_line.shift
|
44
|
+
end
|
45
|
+
|
46
|
+
test "defined some jobs with various mailto argument" do
|
47
|
+
output = Whenever.cron \
|
48
|
+
<<-file
|
49
|
+
every 2.hours do
|
50
|
+
command "blahblah"
|
51
|
+
end
|
52
|
+
|
53
|
+
every 2.hours, mailto: 'john@example.com' do
|
54
|
+
command "blahblah_of_john"
|
55
|
+
command "blahblah2_of_john"
|
56
|
+
end
|
57
|
+
|
58
|
+
every 2.hours, mailto: 'sarah@example.com' do
|
59
|
+
command "blahblah_of_sarah"
|
60
|
+
end
|
61
|
+
|
62
|
+
every 2.hours do
|
63
|
+
command "blahblah_of_martin", mailto: 'martin@example.com'
|
64
|
+
command "blahblah2_of_sarah", mailto: 'sarah@example.com'
|
65
|
+
end
|
66
|
+
|
67
|
+
every 2.hours do
|
68
|
+
command "blahblah2"
|
69
|
+
end
|
70
|
+
file
|
71
|
+
|
72
|
+
output_without_empty_line = lines_without_empty_line(output.lines)
|
73
|
+
|
74
|
+
assert_equal two_hours + " /bin/bash -l -c 'blahblah'", output_without_empty_line.shift
|
75
|
+
assert_equal two_hours + " /bin/bash -l -c 'blahblah2'", output_without_empty_line.shift
|
76
|
+
|
77
|
+
assert_equal 'MAILTO=john@example.com', output_without_empty_line.shift
|
78
|
+
assert_equal two_hours + " /bin/bash -l -c 'blahblah_of_john'", output_without_empty_line.shift
|
79
|
+
assert_equal two_hours + " /bin/bash -l -c 'blahblah2_of_john'", output_without_empty_line.shift
|
80
|
+
|
81
|
+
assert_equal 'MAILTO=sarah@example.com', output_without_empty_line.shift
|
82
|
+
assert_equal two_hours + " /bin/bash -l -c 'blahblah_of_sarah'", output_without_empty_line.shift
|
83
|
+
assert_equal two_hours + " /bin/bash -l -c 'blahblah2_of_sarah'", output_without_empty_line.shift
|
84
|
+
|
85
|
+
assert_equal 'MAILTO=martin@example.com', output_without_empty_line.shift
|
86
|
+
assert_equal two_hours + " /bin/bash -l -c 'blahblah_of_martin'", output_without_empty_line.shift
|
87
|
+
end
|
88
|
+
|
89
|
+
test "defined some jobs with no mailto argument jobs and mailto argument jobs(no mailto jobs should be first line of cron output" do
|
90
|
+
output = Whenever.cron \
|
91
|
+
<<-file
|
92
|
+
every 2.hours, mailto: 'john@example.com' do
|
93
|
+
command "blahblah_of_john"
|
94
|
+
command "blahblah2_of_john"
|
95
|
+
end
|
96
|
+
|
97
|
+
every 2.hours do
|
98
|
+
command "blahblah"
|
99
|
+
end
|
100
|
+
file
|
101
|
+
|
102
|
+
output_without_empty_line = lines_without_empty_line(output.lines)
|
103
|
+
|
104
|
+
assert_equal two_hours + " /bin/bash -l -c 'blahblah'", output_without_empty_line.shift
|
105
|
+
|
106
|
+
assert_equal 'MAILTO=john@example.com', output_without_empty_line.shift
|
107
|
+
assert_equal two_hours + " /bin/bash -l -c 'blahblah_of_john'", output_without_empty_line.shift
|
108
|
+
assert_equal two_hours + " /bin/bash -l -c 'blahblah2_of_john'", output_without_empty_line.shift
|
109
|
+
end
|
110
|
+
|
111
|
+
test "defined some jobs with environment mailto define and various mailto argument" do
|
112
|
+
output = Whenever.cron \
|
113
|
+
<<-file
|
114
|
+
env 'MAILTO', 'default@example.com'
|
115
|
+
|
116
|
+
every 2.hours do
|
117
|
+
command "blahblah"
|
118
|
+
end
|
119
|
+
|
120
|
+
every 2.hours, mailto: 'sarah@example.com' do
|
121
|
+
command "blahblah_by_sarah"
|
122
|
+
end
|
123
|
+
|
124
|
+
every 2.hours do
|
125
|
+
command "blahblah_by_john", mailto: 'john@example.com'
|
126
|
+
end
|
127
|
+
|
128
|
+
every 2.hours do
|
129
|
+
command "blahblah2"
|
130
|
+
end
|
131
|
+
file
|
132
|
+
|
133
|
+
output_without_empty_line = lines_without_empty_line(output.lines)
|
134
|
+
|
135
|
+
assert_equal 'MAILTO=default@example.com', output_without_empty_line.shift
|
136
|
+
assert_equal two_hours + " /bin/bash -l -c 'blahblah'", output_without_empty_line.shift
|
137
|
+
assert_equal two_hours + " /bin/bash -l -c 'blahblah2'", output_without_empty_line.shift
|
138
|
+
|
139
|
+
assert_equal 'MAILTO=sarah@example.com', output_without_empty_line.shift
|
140
|
+
assert_equal two_hours + " /bin/bash -l -c 'blahblah_by_sarah'", output_without_empty_line.shift
|
141
|
+
|
142
|
+
assert_equal 'MAILTO=john@example.com', output_without_empty_line.shift
|
143
|
+
assert_equal two_hours + " /bin/bash -l -c 'blahblah_by_john'", output_without_empty_line.shift
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
class OutputJobsWithMailtoForRolesTest < Whenever::TestCase
|
148
|
+
test "one role requested and specified on the job with mailto argument" do
|
149
|
+
output = Whenever.cron roles: [:role1], :string => \
|
150
|
+
<<-file
|
151
|
+
env 'MAILTO', 'default@example.com'
|
152
|
+
|
153
|
+
every 2.hours, :roles => [:role1] do
|
154
|
+
command "blahblah"
|
155
|
+
end
|
156
|
+
|
157
|
+
every 2.hours, mailto: 'sarah@example.com', :roles => [:role2] do
|
158
|
+
command "blahblah_by_sarah"
|
159
|
+
end
|
160
|
+
file
|
161
|
+
|
162
|
+
output_without_empty_line = lines_without_empty_line(output.lines)
|
163
|
+
|
164
|
+
assert_equal 'MAILTO=default@example.com', output_without_empty_line.shift
|
165
|
+
assert_equal two_hours + " /bin/bash -l -c 'blahblah'", output_without_empty_line.shift
|
166
|
+
assert_nil output_without_empty_line.shift
|
167
|
+
end
|
168
|
+
end
|
data/test/test_helper.rb
CHANGED
@@ -8,30 +8,40 @@ module Whenever::TestHelpers
|
|
8
8
|
Whenever::Job.new(options)
|
9
9
|
end
|
10
10
|
|
11
|
-
def parse_time(time = nil, task = nil, at = nil)
|
12
|
-
Whenever::Output::Cron.new(time, task, at).time_in_cron_syntax
|
11
|
+
def parse_time(time = nil, task = nil, at = nil, options = {})
|
12
|
+
Whenever::Output::Cron.new(time, task, at, options).time_in_cron_syntax
|
13
13
|
end
|
14
14
|
|
15
15
|
def two_hours
|
16
16
|
"0 0,2,4,6,8,10,12,14,16,18,20,22 * * *"
|
17
17
|
end
|
18
18
|
|
19
|
-
def
|
20
|
-
cron = parse_time(Whenever.seconds(
|
19
|
+
def assert_months_and_days_and_hours_and_minutes_equals(expected, time, options = {})
|
20
|
+
cron = parse_time(Whenever.seconds(1, :year), 'some task', time, options)
|
21
|
+
minutes, hours, days, months = cron.split(' ')
|
22
|
+
assert_equal expected, [months, days, hours, minutes]
|
23
|
+
end
|
24
|
+
|
25
|
+
def assert_days_and_hours_and_minutes_equals(expected, time, options = {})
|
26
|
+
cron = parse_time(Whenever.seconds(2, :months), 'some task', time, options)
|
21
27
|
minutes, hours, days, _ = cron.split(' ')
|
22
28
|
assert_equal expected, [days, hours, minutes]
|
23
29
|
end
|
24
30
|
|
25
|
-
def assert_hours_and_minutes_equals(expected, time)
|
26
|
-
cron = parse_time(Whenever.seconds(2, :days), 'some task', time)
|
31
|
+
def assert_hours_and_minutes_equals(expected, time, options = {})
|
32
|
+
cron = parse_time(Whenever.seconds(2, :days), 'some task', time, options)
|
27
33
|
minutes, hours, _ = cron.split(' ')
|
28
34
|
assert_equal expected, [hours, minutes]
|
29
35
|
end
|
30
36
|
|
31
|
-
def assert_minutes_equals(expected, time)
|
32
|
-
cron = parse_time(Whenever.seconds(2, :hours), 'some task', time)
|
37
|
+
def assert_minutes_equals(expected, time, options = {})
|
38
|
+
cron = parse_time(Whenever.seconds(2, :hours), 'some task', time, options)
|
33
39
|
assert_equal expected, cron.split(' ')[0]
|
34
40
|
end
|
41
|
+
|
42
|
+
def lines_without_empty_line(lines)
|
43
|
+
lines.map { |line| line.chomp }.reject { |line| line.empty? }
|
44
|
+
end
|
35
45
|
end
|
36
46
|
|
37
47
|
Whenever::TestCase.send(:include, Whenever::TestHelpers)
|
data/test/unit/cron_test.rb
CHANGED
@@ -67,6 +67,26 @@ class CronParseHoursTest < Whenever::TestCase
|
|
67
67
|
assert_minutes_equals "0", 'midnight'
|
68
68
|
assert_minutes_equals "59", '13:59'
|
69
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 "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)
|
84
|
+
end
|
85
|
+
|
86
|
+
assert_raises ArgumentError do
|
87
|
+
parse_time(Whenever.seconds(1, :hour), nil, -1)
|
88
|
+
end
|
89
|
+
end
|
70
90
|
end
|
71
91
|
|
72
92
|
class CronParseDaysTest < Whenever::TestCase
|
@@ -90,6 +110,17 @@ class CronParseDaysTest < Whenever::TestCase
|
|
90
110
|
assert_hours_and_minutes_equals %w(23 59), 'March 21 11:59 pM'
|
91
111
|
end
|
92
112
|
|
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
|
+
|
93
124
|
should "parse correctly when given an 'at' with hours as an Integer" do
|
94
125
|
# first param is an array with [hours, minutes]
|
95
126
|
assert_hours_and_minutes_equals %w(1 0), 1
|
@@ -98,6 +129,16 @@ class CronParseDaysTest < Whenever::TestCase
|
|
98
129
|
assert_hours_and_minutes_equals %w(19 0), 19
|
99
130
|
assert_hours_and_minutes_equals %w(23 0), 23
|
100
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)
|
136
|
+
end
|
137
|
+
|
138
|
+
assert_raises ArgumentError do
|
139
|
+
parse_time(Whenever.seconds(1, :day), nil, -1)
|
140
|
+
end
|
141
|
+
end
|
101
142
|
end
|
102
143
|
|
103
144
|
class CronParseMonthsTest < Whenever::TestCase
|
@@ -132,12 +173,96 @@ class CronParseMonthsTest < Whenever::TestCase
|
|
132
173
|
assert_days_and_hours_and_minutes_equals %w(23 0 0), 'march 22nd at midnight' # looks like midnight means the next day
|
133
174
|
end
|
134
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
|
192
|
+
|
135
193
|
should "parse correctly when given an 'at' with days as an Integer" do
|
136
194
|
# first param is an array with [days, hours, minutes]
|
137
195
|
assert_days_and_hours_and_minutes_equals %w(1 0 0), 1
|
138
196
|
assert_days_and_hours_and_minutes_equals %w(15 0 0), 15
|
139
197
|
assert_days_and_hours_and_minutes_equals %w(29 0 0), 29
|
140
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)
|
203
|
+
end
|
204
|
+
|
205
|
+
assert_raises ArgumentError do
|
206
|
+
parse_time(Whenever.seconds(1, :month), nil, -1)
|
207
|
+
end
|
208
|
+
end
|
209
|
+
end
|
210
|
+
|
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
|
215
|
+
|
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
|
224
|
+
|
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
|
231
|
+
end
|
232
|
+
|
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
|
141
266
|
end
|
142
267
|
|
143
268
|
class CronParseDaysOfWeekTest < Whenever::TestCase
|
@@ -191,10 +316,10 @@ class CronParseShortcutsTest < Whenever::TestCase
|
|
191
316
|
end
|
192
317
|
|
193
318
|
should "convert time-based shortcuts to times" do
|
194
|
-
assert_equal '0 0 1 * *',
|
195
|
-
assert_equal '0 0 * * *',
|
196
|
-
assert_equal '0 * * * *',
|
197
|
-
assert_equal '0 0 1
|
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)
|
198
323
|
assert_equal '0 0 1,8,15,22 * *', parse_time(:week)
|
199
324
|
end
|
200
325
|
|
@@ -235,6 +360,7 @@ class CronParseRawTest < Whenever::TestCase
|
|
235
360
|
should "return the same cron sytax" do
|
236
361
|
crons = ['0 0 27-31 * *', '* * * * *', '2/3 1,9,22 11-26 1-6 *', '*/5 6-23 * * *',
|
237
362
|
"*\t*\t*\t*\t*",
|
363
|
+
'7 17 * * FRI', '7 17 * * Mon-Fri', '30 12 * Jun *', '30 12 * Jun-Aug *',
|
238
364
|
'@reboot', '@yearly', '@annually', '@monthly', '@weekly',
|
239
365
|
'@daily', '@midnight', '@hourly']
|
240
366
|
crons.each do |cron|
|
@@ -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
|