cwninja-whenever 0.1.5.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.
- data/CHANGELOG.rdoc +26 -0
- data/README.rdoc +127 -0
- data/Rakefile +26 -0
- data/bin/whenever +42 -0
- data/bin/wheneverize +69 -0
- data/lib/base.rb +15 -0
- data/lib/command_line.rb +68 -0
- data/lib/job_list.rb +90 -0
- data/lib/job_types/default.rb +27 -0
- data/lib/job_types/rake_task.rb +12 -0
- data/lib/job_types/runner.rb +12 -0
- data/lib/outputs/cron.rb +104 -0
- data/lib/version.rb +10 -0
- data/lib/whenever.rb +19 -0
- data/test/command_line_test.rb +63 -0
- data/test/cron_test.rb +187 -0
- data/test/output_command_test.rb +70 -0
- data/test/output_env_test.rb +23 -0
- data/test/output_rake_test.rb +74 -0
- data/test/output_runner_test.rb +125 -0
- data/test/test_helper.rb +33 -0
- data/whenever.gemspec +39 -0
- metadata +118 -0
@@ -0,0 +1,63 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + "/test_helper")
|
2
|
+
|
3
|
+
class CommandLineTest < Test::Unit::TestCase
|
4
|
+
WHENEVER_CRON_CONTENTS = "Whenever CRON Contents"
|
5
|
+
EXPECTED_WHENEVER_GENERATED_SEGMENT = CommandLine::START_MARKER + "\n" + WHENEVER_CRON_CONTENTS + "\n" + CommandLine::END_MARKER
|
6
|
+
|
7
|
+
context "Some crontab to write" do
|
8
|
+
setup do
|
9
|
+
Whenever.stubs(:cron).returns(WHENEVER_CRON_CONTENTS)
|
10
|
+
@command_line.stubs(:write_crontab).raises("Don't actually write the crontab, put an expectation on it!")
|
11
|
+
end
|
12
|
+
|
13
|
+
context "An empty crontab" do
|
14
|
+
setup do
|
15
|
+
@command_line = CommandLine.new
|
16
|
+
@command_line.stubs(:read_crontab).returns("")
|
17
|
+
end
|
18
|
+
|
19
|
+
should "just write a fresh crontab" do
|
20
|
+
@command_line.expects(:write_crontab).with(EXPECTED_WHENEVER_GENERATED_SEGMENT)
|
21
|
+
@command_line.update!
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
context "A crontab with some content" do
|
26
|
+
setup do
|
27
|
+
@command_line = CommandLine.new
|
28
|
+
@command_line.stubs(:read_crontab).returns("Hello World")
|
29
|
+
end
|
30
|
+
|
31
|
+
should "Put the existing content at the top" do
|
32
|
+
@command_line.expects(:write_crontab).with("Hello World\n" + EXPECTED_WHENEVER_GENERATED_SEGMENT)
|
33
|
+
@command_line.update!
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
context "A crontab with some content, and some existing whenever jobs" do
|
38
|
+
setup do
|
39
|
+
@command_line = CommandLine.new
|
40
|
+
@command_line.stubs(:read_crontab).returns("Hello World\n#{CommandLine::START_MARKER}\nSome other old content to be overridden\n#{CommandLine::END_MARKER}")
|
41
|
+
end
|
42
|
+
|
43
|
+
should "Put the existing content at the top" do
|
44
|
+
@command_line.expects(:write_crontab).with("Hello World\n" + EXPECTED_WHENEVER_GENERATED_SEGMENT)
|
45
|
+
@command_line.update!
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
|
50
|
+
context "A crontab with some content at the end, and some existing whenever jobs" do
|
51
|
+
setup do
|
52
|
+
@command_line = CommandLine.new
|
53
|
+
@command_line.stubs(:read_crontab).returns("#{CommandLine::START_MARKER}\nSome other old content to be overridden\n#{CommandLine::END_MARKER}\nHello World")
|
54
|
+
end
|
55
|
+
|
56
|
+
should "Put the existing content at the top" do
|
57
|
+
@command_line.expects(:write_crontab).with(EXPECTED_WHENEVER_GENERATED_SEGMENT + "\nHello World")
|
58
|
+
@command_line.update!
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|
data/test/cron_test.rb
ADDED
@@ -0,0 +1,187 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + "/test_helper")
|
2
|
+
|
3
|
+
class CronTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
context "When parsing time in minutes" do
|
6
|
+
should "raise if less than 1 minute" do
|
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
|
14
|
+
end
|
15
|
+
|
16
|
+
# For santity, do some tests on straight String
|
17
|
+
should "parse correctly" do
|
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
|
24
|
+
end
|
25
|
+
|
26
|
+
# Test all minutes
|
27
|
+
(2..59).each do |num|
|
28
|
+
should "parse correctly for #{num} minutes" do
|
29
|
+
start = 0
|
30
|
+
start += num unless 60.modulo(num).zero?
|
31
|
+
minutes = (start..59).step(num).to_a
|
32
|
+
|
33
|
+
assert_equal "#{minutes.join(',')} * * * *", parse_time(num.minutes)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
context "When parsing time in hours" do
|
39
|
+
should "parse correctly" do
|
40
|
+
assert_equal '0 * * * *', parse_time(1.hour)
|
41
|
+
assert_equal '0 0,2,4,6,8,10,12,14,16,18,20,22 * * *', parse_time(2.hours)
|
42
|
+
assert_equal '0 0,3,6,9,12,15,18,21 * * *', parse_time(3.hours)
|
43
|
+
assert_equal '0 5,10,15,20 * * *', parse_time(5.hours)
|
44
|
+
assert_equal '0 17 * * *', parse_time(17.hours)
|
45
|
+
assert_not_equal '0 24 * * *', parse_time(24.hours) # 24 hours bumps up into the day range
|
46
|
+
end
|
47
|
+
|
48
|
+
(2..23).each do |num|
|
49
|
+
should "parse correctly for #{num} hours" do
|
50
|
+
start = 0
|
51
|
+
start += num unless 24.modulo(num).zero?
|
52
|
+
hours = (start..23).step(num).to_a
|
53
|
+
|
54
|
+
assert_equal "0 #{hours.join(',')} * * *", parse_time(num.hours)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
should "parse correctly when given an 'at' with minutes as an Integer" do
|
59
|
+
assert_minutes_equals "1", 1
|
60
|
+
assert_minutes_equals "14", 14
|
61
|
+
assert_minutes_equals "27", 27
|
62
|
+
assert_minutes_equals "55", 55
|
63
|
+
end
|
64
|
+
|
65
|
+
should "parse correctly when given an 'at' with minutes as a Time" do
|
66
|
+
# Basically just testing that Chronic parses some times and we get the minutes out of it
|
67
|
+
assert_minutes_equals "1", '3:01am'
|
68
|
+
assert_minutes_equals "1", 'January 21 2:01 PM'
|
69
|
+
assert_minutes_equals "0", 'midnight'
|
70
|
+
assert_minutes_equals "59", '13:59'
|
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 correctly when given an 'at' with days, hours, minutes as a Time" do
|
121
|
+
# first param is an array with [days, hours, minutes]
|
122
|
+
assert_days_and_hours_and_minutes_equals %w(1 3 45), 'January 1st 3:45am'
|
123
|
+
assert_days_and_hours_and_minutes_equals %w(11 23 0), 'Feb 11 11PM'
|
124
|
+
assert_days_and_hours_and_minutes_equals %w(22 1 1), 'march 22nd at 1:01 am'
|
125
|
+
assert_days_and_hours_and_minutes_equals %w(23 0 0), 'march 22nd at midnight' # looks like midnight means the next day
|
126
|
+
end
|
127
|
+
|
128
|
+
should "parse correctly when given an 'at' with days as an Integer" do
|
129
|
+
# first param is an array with [days, hours, minutes]
|
130
|
+
assert_days_and_hours_and_minutes_equals %w(1 0 0), 1
|
131
|
+
assert_days_and_hours_and_minutes_equals %w(15 0 0), 15
|
132
|
+
assert_days_and_hours_and_minutes_equals %w(29 0 0), 29
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
context "When parsing time in days (of week)" do
|
137
|
+
should "parse days of the week correctly" do
|
138
|
+
{
|
139
|
+
'sun' => %w(sun Sunday SUNDAY SUN),
|
140
|
+
'mon' => %w(mon Monday MONDAY MON),
|
141
|
+
'tue' => %w(tue tues Tuesday TUESDAY TUE),
|
142
|
+
'wed' => %w(wed Wednesday WEDNESDAY WED),
|
143
|
+
'thu' => %w(thu thurs thur Thursday THURSDAY THU),
|
144
|
+
'fri' => %w(fri Friday FRIDAY FRI),
|
145
|
+
'sat' => %w(sat Saturday SATURDAY SAT)
|
146
|
+
}.each do |day, day_tests|
|
147
|
+
day_tests.each do |day_test|
|
148
|
+
assert_equal "0 0 * * #{day}", parse_time(day_test)
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
should "parse weekday correctly" do
|
154
|
+
assert_equal '0 0 * * mon-fri', parse_time('weekday')
|
155
|
+
assert_equal '0 0 * * mon-fri', parse_time('Weekdays')
|
156
|
+
end
|
157
|
+
|
158
|
+
should "parse weekend correctly" do
|
159
|
+
assert_equal '0 0 * * sat,sun', parse_time('weekend')
|
160
|
+
assert_equal '0 0 * * sat,sun', parse_time('Weekends')
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
private
|
165
|
+
|
166
|
+
def assert_days_and_hours_and_minutes_equals(expected, time)
|
167
|
+
cron = parse_time(2.months, 'some task', time)
|
168
|
+
minutes, hours, days, *garbage = cron.split(' ')
|
169
|
+
assert_equal expected, [days, hours, minutes]
|
170
|
+
end
|
171
|
+
|
172
|
+
def assert_hours_and_minutes_equals(expected, time)
|
173
|
+
cron = parse_time(2.days, 'some task', time)
|
174
|
+
minutes, hours, *garbage = cron.split(' ')
|
175
|
+
assert_equal expected, [hours, minutes]
|
176
|
+
end
|
177
|
+
|
178
|
+
def assert_minutes_equals(expected, time)
|
179
|
+
cron = parse_time(2.hours, 'some task', time)
|
180
|
+
assert_equal expected, cron.split(' ')[0]
|
181
|
+
end
|
182
|
+
|
183
|
+
def parse_time(time = nil, task = nil, at = nil)
|
184
|
+
Whenever::Output::Cron.new(time, task, at).time_in_cron_syntax
|
185
|
+
end
|
186
|
+
|
187
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + "/test_helper")
|
2
|
+
|
3
|
+
class OutputCommandTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
context "A plain command" do
|
6
|
+
setup do
|
7
|
+
@output = Whenever.cron \
|
8
|
+
<<-file
|
9
|
+
every 2.hours do
|
10
|
+
command "blahblah"
|
11
|
+
end
|
12
|
+
file
|
13
|
+
end
|
14
|
+
|
15
|
+
should "output the command" do
|
16
|
+
assert_match /^.+ .+ .+ .+ blahblah$/, @output
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
context "A command when the cron_log is set" do
|
21
|
+
setup do
|
22
|
+
@output = Whenever.cron \
|
23
|
+
<<-file
|
24
|
+
set :cron_log, 'logfile.log'
|
25
|
+
every 2.hours do
|
26
|
+
command "blahblah"
|
27
|
+
end
|
28
|
+
file
|
29
|
+
end
|
30
|
+
|
31
|
+
should "output the command with the log syntax appended" do
|
32
|
+
assert_match /^.+ .+ .+ .+ blahblah >> logfile.log 2>&1$/, @output
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
context "A command when the cron_log is set and the comand overrides it" do
|
37
|
+
setup do
|
38
|
+
@output = Whenever.cron \
|
39
|
+
<<-file
|
40
|
+
set :cron_log, 'logfile.log'
|
41
|
+
every 2.hours do
|
42
|
+
command "blahblah", :cron_log => 'otherlog.log'
|
43
|
+
end
|
44
|
+
file
|
45
|
+
end
|
46
|
+
|
47
|
+
should "output the command with the log syntax appended" do
|
48
|
+
assert_no_match /.+ .+ .+ .+ blahblah >> logfile.log 2>&1/, @output
|
49
|
+
assert_match /^.+ .+ .+ .+ blahblah >> otherlog.log 2>&1$/, @output
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
context "A command when the cron_log is set and the comand rejects it" do
|
54
|
+
setup do
|
55
|
+
@output = Whenever.cron \
|
56
|
+
<<-file
|
57
|
+
set :cron_log, 'logfile.log'
|
58
|
+
every 2.hours do
|
59
|
+
command "blahblah", :cron_log => false
|
60
|
+
end
|
61
|
+
file
|
62
|
+
end
|
63
|
+
|
64
|
+
should "output the command without the log syntax appended" do
|
65
|
+
assert_no_match /.+ .+ .+ .+ blahblah >> logfile.log 2>&1/, @output
|
66
|
+
assert_match /^.+ .+ .+ .+ blahblah$/, @output
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + "/test_helper")
|
2
|
+
|
3
|
+
class OutputEnvTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
context "The output from Whenever with environment variables set" do
|
6
|
+
setup do
|
7
|
+
@output = Whenever.cron \
|
8
|
+
<<-file
|
9
|
+
env :MYVAR, 'blah'
|
10
|
+
env 'MAILTO', "someone@example.com"
|
11
|
+
file
|
12
|
+
end
|
13
|
+
|
14
|
+
should "output MYVAR environment variable" do
|
15
|
+
assert_match "MYVAR=blah", @output
|
16
|
+
end
|
17
|
+
|
18
|
+
should "output MAILTO environment variable" do
|
19
|
+
assert_match "MAILTO=someone@example.com", @output
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + "/test_helper")
|
2
|
+
|
3
|
+
class OutputRakeTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
# Rake are generated in an almost identical way to runners so we
|
6
|
+
# only need some basic tests to ensure they are output correctly
|
7
|
+
|
8
|
+
context "A rake command with path set" do
|
9
|
+
setup do
|
10
|
+
@output = Whenever.cron \
|
11
|
+
<<-file
|
12
|
+
set :path, '/my/path'
|
13
|
+
every 2.hours do
|
14
|
+
rake "blahblah"
|
15
|
+
end
|
16
|
+
file
|
17
|
+
end
|
18
|
+
|
19
|
+
should "output the rake command using that path" do
|
20
|
+
assert_match two_hours + ' cd /my/path && RAILS_ENV=production /usr/bin/env rake blahblah', @output
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
context "A rake command that overrides the path set" do
|
25
|
+
setup do
|
26
|
+
@output = Whenever.cron \
|
27
|
+
<<-file
|
28
|
+
set :path, '/my/path'
|
29
|
+
every 2.hours do
|
30
|
+
rake "blahblah", :path => '/some/other/path'
|
31
|
+
end
|
32
|
+
file
|
33
|
+
end
|
34
|
+
|
35
|
+
should "output the rake command using that path" do
|
36
|
+
assert_match two_hours + ' cd /some/other/path && RAILS_ENV=production /usr/bin/env rake blahblah', @output
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
context "A rake command with environment set" do
|
41
|
+
setup do
|
42
|
+
@output = Whenever.cron \
|
43
|
+
<<-file
|
44
|
+
set :environment, :silly
|
45
|
+
set :path, '/my/path'
|
46
|
+
every 2.hours do
|
47
|
+
rake "blahblah"
|
48
|
+
end
|
49
|
+
file
|
50
|
+
end
|
51
|
+
|
52
|
+
should "output the rake command using that environment" do
|
53
|
+
assert_match two_hours + ' cd /my/path && RAILS_ENV=silly /usr/bin/env rake blahblah', @output
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
context "A rake command that overrides the environment set" do
|
58
|
+
setup do
|
59
|
+
@output = Whenever.cron \
|
60
|
+
<<-file
|
61
|
+
set :environment, :silly
|
62
|
+
set :path, '/my/path'
|
63
|
+
every 2.hours do
|
64
|
+
rake "blahblah", :environment => :serious
|
65
|
+
end
|
66
|
+
file
|
67
|
+
end
|
68
|
+
|
69
|
+
should "output the rake command using that environment" do
|
70
|
+
assert_match two_hours + ' cd /my/path && RAILS_ENV=serious /usr/bin/env rake blahblah', @output
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
@@ -0,0 +1,125 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + "/test_helper")
|
2
|
+
|
3
|
+
class OutputRunnerTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
context "A runner with path set" do
|
6
|
+
setup do
|
7
|
+
@output = Whenever.cron \
|
8
|
+
<<-file
|
9
|
+
set :path, '/my/path'
|
10
|
+
every 2.hours do
|
11
|
+
runner "blahblah"
|
12
|
+
end
|
13
|
+
file
|
14
|
+
end
|
15
|
+
|
16
|
+
should "output the runner using that path" do
|
17
|
+
assert_match two_hours + ' /my/path/script/runner -e production "blahblah"', @output
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
context "A runner that overrides the path set" do
|
22
|
+
setup do
|
23
|
+
@output = Whenever.cron \
|
24
|
+
<<-file
|
25
|
+
set :path, '/my/path'
|
26
|
+
every 2.hours do
|
27
|
+
runner "blahblah", :path => '/some/other/path'
|
28
|
+
end
|
29
|
+
file
|
30
|
+
end
|
31
|
+
|
32
|
+
should "output the runner using that path" do
|
33
|
+
assert_match two_hours + ' /some/other/path/script/runner -e production "blahblah"', @output
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
context "A runner with no path set and RAILS_ROOT defined" do
|
38
|
+
setup do
|
39
|
+
Whenever.stubs(:path).returns('/my/path')
|
40
|
+
|
41
|
+
@output = Whenever.cron \
|
42
|
+
<<-file
|
43
|
+
every 2.hours do
|
44
|
+
runner "blahblah"
|
45
|
+
end
|
46
|
+
file
|
47
|
+
end
|
48
|
+
|
49
|
+
should "output the runner using that path" do
|
50
|
+
assert_match two_hours + ' /my/path/script/runner -e production "blahblah"', @output
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
context "A runner with path set AND RAILS_ROOT defined" do
|
55
|
+
setup do
|
56
|
+
Whenever.stubs(:path).returns('/my/rails/path')
|
57
|
+
|
58
|
+
@output = Whenever.cron \
|
59
|
+
<<-file
|
60
|
+
set :path, '/my/path'
|
61
|
+
every 2.hours do
|
62
|
+
runner "blahblah"
|
63
|
+
end
|
64
|
+
file
|
65
|
+
end
|
66
|
+
|
67
|
+
should "use the path" do
|
68
|
+
assert_match two_hours + ' /my/path/script/runner -e production "blahblah"', @output
|
69
|
+
assert_no_match /\/rails\/path/, @output
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
context "A runner with no path set and no RAILS_ROOT defined" do
|
74
|
+
setup do
|
75
|
+
Whenever.stubs(:path).returns(nil)
|
76
|
+
|
77
|
+
@input = <<-file
|
78
|
+
every 2.hours do
|
79
|
+
runner "blahblah"
|
80
|
+
end
|
81
|
+
file
|
82
|
+
end
|
83
|
+
|
84
|
+
should "raise an exception" do
|
85
|
+
assert_raises ArgumentError do
|
86
|
+
Whenever.cron(@input)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
context "A runner with an environment set" do
|
92
|
+
setup do
|
93
|
+
@output = Whenever.cron \
|
94
|
+
<<-file
|
95
|
+
set :environment, :silly
|
96
|
+
set :path, '/my/path'
|
97
|
+
every 2.hours do
|
98
|
+
runner "blahblah"
|
99
|
+
end
|
100
|
+
file
|
101
|
+
end
|
102
|
+
|
103
|
+
should "output the runner using that environment" do
|
104
|
+
assert_match two_hours + ' /my/path/script/runner -e silly "blahblah"', @output
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
context "A runner that overrides the environment set" do
|
109
|
+
setup do
|
110
|
+
@output = Whenever.cron \
|
111
|
+
<<-file
|
112
|
+
set :environment, :silly
|
113
|
+
set :path, '/my/path'
|
114
|
+
every 2.hours do
|
115
|
+
runner "blahblah", :environment => :serious
|
116
|
+
end
|
117
|
+
file
|
118
|
+
end
|
119
|
+
|
120
|
+
should "output the runner using that environment" do
|
121
|
+
assert_match two_hours + ' /my/path/script/runner -e serious "blahblah"', @output
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
end
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'test/unit'
|
3
|
+
|
4
|
+
require File.expand_path(File.dirname(__FILE__) + "/../lib/whenever")
|
5
|
+
|
6
|
+
begin
|
7
|
+
require 'shoulda'
|
8
|
+
rescue LoadError
|
9
|
+
warn 'To test Whenever you need the shoulda gem:'
|
10
|
+
warn '$ sudo gem install thoughtbot-shoulda'
|
11
|
+
exit(1)
|
12
|
+
end
|
13
|
+
|
14
|
+
begin
|
15
|
+
require 'mocha'
|
16
|
+
rescue LoadError
|
17
|
+
warn 'To test Whenever you need the mocha gem:'
|
18
|
+
warn '$ sudo gem install mocha'
|
19
|
+
exit(1)
|
20
|
+
end
|
21
|
+
|
22
|
+
|
23
|
+
module TestExtensions
|
24
|
+
|
25
|
+
def two_hours
|
26
|
+
"0 0,2,4,6,8,10,12,14,16,18,20,22 * * *"
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
class Test::Unit::TestCase
|
32
|
+
include TestExtensions
|
33
|
+
end
|
data/whenever.gemspec
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = %q{whenever}
|
5
|
+
s.version = "0.1.5.1"
|
6
|
+
|
7
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
|
+
s.authors = ["Javan Makhmali"]
|
9
|
+
s.date = %q{2009-02-20}
|
10
|
+
s.description = %q{Provides clean ruby syntax for defining messy cron jobs and running them Whenever.}
|
11
|
+
s.email = %q{javan@javan.us}
|
12
|
+
s.executables = ["whenever", "wheneverize"]
|
13
|
+
s.extra_rdoc_files = ["bin/whenever", "bin/wheneverize", "CHANGELOG.rdoc", "lib/base.rb", "lib/command_line.rb", "lib/job_list.rb", "lib/job_types/default.rb", "lib/job_types/rake_task.rb", "lib/job_types/runner.rb", "lib/outputs/cron.rb", "lib/version.rb", "lib/whenever.rb", "README.rdoc"]
|
14
|
+
s.files = ["bin/whenever", "bin/wheneverize", "CHANGELOG.rdoc", "lib/base.rb", "lib/command_line.rb", "lib/job_list.rb", "lib/job_types/default.rb", "lib/job_types/rake_task.rb", "lib/job_types/runner.rb", "lib/outputs/cron.rb", "lib/version.rb", "lib/whenever.rb", "Rakefile", "README.rdoc", "test/command_line_test.rb", "test/cron_test.rb", "test/output_command_test.rb", "test/output_env_test.rb", "test/output_rake_test.rb", "test/output_runner_test.rb", "test/test_helper.rb", "whenever.gemspec", "Manifest"]
|
15
|
+
s.has_rdoc = true
|
16
|
+
s.homepage = %q{http://github.com/javan/whenever}
|
17
|
+
s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Whenever", "--main", "README.rdoc"]
|
18
|
+
s.require_paths = ["lib"]
|
19
|
+
s.rubyforge_project = %q{whenever}
|
20
|
+
s.rubygems_version = %q{1.3.0}
|
21
|
+
s.summary = %q{Provides clean ruby syntax for defining messy cron jobs and running them Whenever.}
|
22
|
+
s.test_files = ["test/command_line_test.rb", "test/cron_test.rb", "test/output_command_test.rb", "test/output_env_test.rb", "test/output_rake_test.rb", "test/output_runner_test.rb", "test/test_helper.rb"]
|
23
|
+
|
24
|
+
if s.respond_to? :specification_version then
|
25
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
26
|
+
s.specification_version = 2
|
27
|
+
|
28
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
29
|
+
s.add_runtime_dependency(%q<chronic>, [">= 0.2.3"])
|
30
|
+
s.add_runtime_dependency(%q<activesupport>, [">= 1.3.0"])
|
31
|
+
else
|
32
|
+
s.add_dependency(%q<chronic>, [">= 0.2.3"])
|
33
|
+
s.add_dependency(%q<activesupport>, [">= 1.3.0"])
|
34
|
+
end
|
35
|
+
else
|
36
|
+
s.add_dependency(%q<chronic>, [">= 0.2.3"])
|
37
|
+
s.add_dependency(%q<activesupport>, [">= 1.3.0"])
|
38
|
+
end
|
39
|
+
end
|