whenever 0.9.2 → 0.9.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,268 +1,207 @@
1
- require File.expand_path(File.dirname(__FILE__) + "/../test_helper")
2
-
3
- class OutputAtTest < Test::Unit::TestCase
4
-
5
- context "weekday at a (single) given time" do
6
- setup do
7
- @output = Whenever.cron \
8
- <<-file
9
- set :job_template, nil
10
- every "weekday", :at => '5:02am' do
11
- command "blahblah"
12
- end
13
- file
14
- end
15
-
16
- should "output the command using that time" do
17
- assert_match '2 5 * * 1-5 blahblah', @output
18
- end
1
+ require 'test_helper'
2
+
3
+ class OutputAtTest < Whenever::TestCase
4
+ test "weekday at a (single) given time" do
5
+ output = Whenever.cron \
6
+ <<-file
7
+ set :job_template, nil
8
+ every "weekday", :at => '5:02am' do
9
+ command "blahblah"
10
+ end
11
+ file
12
+
13
+ assert_match '2 5 * * 1-5 blahblah', output
19
14
  end
20
-
21
- context "weekday at a multiple diverse times, via an array" do
22
- setup do
23
- @output = Whenever.cron \
24
- <<-file
25
- set :job_template, nil
26
- every "weekday", :at => %w(5:02am 3:52pm) do
27
- command "blahblah"
28
- end
29
- file
30
- end
31
-
32
- should "output the commands for both times given" do
33
- assert_match '2 5 * * 1-5 blahblah', @output
34
- assert_match '52 15 * * 1-5 blahblah', @output
35
- end
15
+
16
+ test "weekday at a multiple diverse times, via an array" do
17
+ output = Whenever.cron \
18
+ <<-file
19
+ set :job_template, nil
20
+ every "weekday", :at => %w(5:02am 3:52pm) do
21
+ command "blahblah"
22
+ end
23
+ file
24
+
25
+ assert_match '2 5 * * 1-5 blahblah', output
26
+ assert_match '52 15 * * 1-5 blahblah', output
36
27
  end
37
-
38
- context "weekday at a multiple diverse times, comma separated" do
39
- setup do
40
- @output = Whenever.cron \
41
- <<-file
42
- set :job_template, nil
43
- every "weekday", :at => '5:02am, 3:52pm' do
44
- command "blahblah"
45
- end
46
- file
47
- end
48
-
49
- should "output the commands for both times given" do
50
- assert_match '2 5 * * 1-5 blahblah', @output
51
- assert_match '52 15 * * 1-5 blahblah', @output
52
- end
28
+
29
+ test "weekday at a multiple diverse times, comma separated" do
30
+ output = Whenever.cron \
31
+ <<-file
32
+ set :job_template, nil
33
+ every "weekday", :at => '5:02am, 3:52pm' do
34
+ command "blahblah"
35
+ end
36
+ file
37
+
38
+ assert_match '2 5 * * 1-5 blahblah', output
39
+ assert_match '52 15 * * 1-5 blahblah', output
53
40
  end
54
-
55
- context "weekday at a multiple aligned times" do
56
- setup do
57
- @output = Whenever.cron \
58
- <<-file
59
- set :job_template, nil
60
- every "weekday", :at => '5:02am, 3:02pm' do
61
- command "blahblah"
62
- end
63
- file
64
- end
65
-
66
- should "output the command using one entry because the times are aligned" do
67
- assert_match '2 5,15 * * 1-5 blahblah', @output
68
- end
41
+
42
+ test "weekday at a multiple aligned times" do
43
+ output = Whenever.cron \
44
+ <<-file
45
+ set :job_template, nil
46
+ every "weekday", :at => '5:02am, 3:02pm' do
47
+ command "blahblah"
48
+ end
49
+ file
50
+
51
+ assert_match '2 5,15 * * 1-5 blahblah', output
69
52
  end
70
-
71
- context "various days at a various aligned times" do
72
- setup do
73
- @output = Whenever.cron \
74
- <<-file
75
- set :job_template, nil
76
- every "mon,wed,fri", :at => '5:02am, 3:02pm' do
77
- command "blahblah"
78
- end
79
- file
80
- end
81
-
82
- should "output the command using one entry because the times are aligned" do
83
- assert_match '2 5,15 * * 1,3,5 blahblah', @output
84
- end
53
+
54
+ test "various days at a various aligned times" do
55
+ output = Whenever.cron \
56
+ <<-file
57
+ set :job_template, nil
58
+ every "mon,wed,fri", :at => '5:02am, 3:02pm' do
59
+ command "blahblah"
60
+ end
61
+ file
62
+
63
+ assert_match '2 5,15 * * 1,3,5 blahblah', output
85
64
  end
86
-
87
- context "various days at a various aligned times using a runner" do
88
- setup do
89
- @output = Whenever.cron \
90
- <<-file
91
- set :job_template, nil
92
- set :path, '/your/path'
93
- every "mon,wed,fri", :at => '5:02am, 3:02pm' do
94
- runner "blahblah"
95
- end
96
- file
97
- end
98
-
99
- should "output the runner using one entry because the times are aligned" do
100
- assert_match %(2 5,15 * * 1,3,5 cd /your/path && script/runner -e production 'blahblah'), @output
101
- end
65
+
66
+ test "various days at a various aligned times using a runner" do
67
+ output = Whenever.cron \
68
+ <<-file
69
+ set :job_template, nil
70
+ set :path, '/your/path'
71
+ every "mon,wed,fri", :at => '5:02am, 3:02pm' do
72
+ runner "blahblah"
73
+ end
74
+ file
75
+
76
+ assert_match %(2 5,15 * * 1,3,5 cd /your/path && script/runner -e production 'blahblah'), output
102
77
  end
103
-
104
- context "various days at a various aligned times using a rake task" do
105
- setup do
106
- @output = Whenever.cron \
107
- <<-file
108
- set :job_template, nil
109
- set :path, '/your/path'
110
- every "mon,wed,fri", :at => '5:02am, 3:02pm' do
111
- rake "blah:blah"
112
- end
113
- file
114
- end
115
-
116
- should "output the rake task using one entry because the times are aligned" do
117
- assert_match '2 5,15 * * 1,3,5 cd /your/path && RAILS_ENV=production bundle exec rake blah:blah --silent', @output
118
- end
78
+
79
+ test "various days at a various aligned times using a rake task" do
80
+ output = Whenever.cron \
81
+ <<-file
82
+ set :job_template, nil
83
+ set :path, '/your/path'
84
+ every "mon,wed,fri", :at => '5:02am, 3:02pm' do
85
+ rake "blah:blah"
86
+ end
87
+ file
88
+
89
+ assert_match '2 5,15 * * 1,3,5 cd /your/path && RAILS_ENV=production bundle exec rake blah:blah --silent', output
119
90
  end
120
-
121
- context "A command every 1.month at very diverse times" do
122
- setup do
123
- @output = Whenever.cron \
124
- <<-file
125
- set :job_template, nil
126
- every [1.month, 1.day], :at => 'january 5:02am, june 17th at 2:22pm, june 3rd at 3:33am' do
127
- command "blahblah"
128
- end
129
- file
130
- end
131
-
132
- should "output 6 commands since none align" do
133
- # The 1.month commands
134
- assert_match '2 5 1 * * blahblah', @output
135
- assert_match '22 14 17 * * blahblah', @output
136
- assert_match '33 3 3 * * blahblah', @output
137
-
138
- # The 1.day commands
139
- assert_match '2 5 * * * blahblah', @output
140
- assert_match '22 14 * * * blahblah', @output
141
- assert_match '33 3 * * * blahblah', @output
142
- end
91
+
92
+ test "A command every 1.month at very diverse times" do
93
+ output = Whenever.cron \
94
+ <<-file
95
+ set :job_template, nil
96
+ every [1.month, 1.day], :at => 'january 5:02am, june 17th at 2:22pm, june 3rd at 3:33am' do
97
+ command "blahblah"
98
+ end
99
+ file
100
+
101
+ # The 1.month commands
102
+ assert_match '2 5 1 * * blahblah', output
103
+ assert_match '22 14 17 * * blahblah', output
104
+ assert_match '33 3 3 * * blahblah', output
105
+
106
+ # The 1.day commands
107
+ assert_match '2 5 * * * blahblah', output
108
+ assert_match '22 14 * * * blahblah', output
109
+ assert_match '33 3 * * * blahblah', output
143
110
  end
144
-
145
- context "Multiple commands output every :reboot" do
146
- setup do
147
- @output = Whenever.cron \
148
- <<-file
149
- set :job_template, nil
150
- every :reboot do
151
- command "command_1"
152
- command "command_2"
153
- end
154
- file
155
- end
156
-
157
- should "output both commands @reboot" do
158
- assert_match "@reboot command_1", @output
159
- assert_match "@reboot command_2", @output
160
- end
111
+
112
+ test "Multiple commands output every :reboot" do
113
+ output = Whenever.cron \
114
+ <<-file
115
+ set :job_template, nil
116
+ every :reboot do
117
+ command "command_1"
118
+ command "command_2"
119
+ end
120
+ file
121
+
122
+ assert_match "@reboot command_1", output
123
+ assert_match "@reboot command_2", output
161
124
  end
162
-
163
- context "Many different job types output every :day" do
164
- setup do
165
- @output = Whenever.cron \
166
- <<-file
167
- set :job_template, nil
168
- set :path, '/your/path'
169
- every :daily do
170
- rake "blah:blah"
171
- runner "runner_1"
172
- command "command_1"
173
- runner "runner_2"
174
- command "command_2"
175
- end
176
- file
177
- end
178
-
179
- should "output all of the commands @daily" do
180
- assert_match '@daily cd /your/path && RAILS_ENV=production bundle exec rake blah:blah --silent', @output
181
- assert_match %(@daily cd /your/path && script/runner -e production 'runner_1'), @output
182
- assert_match '@daily command_1', @output
183
- assert_match %(@daily cd /your/path && script/runner -e production 'runner_2'), @output
184
- assert_match '@daily command_2', @output
185
- end
125
+
126
+ test "Many different job types output every :day" do
127
+ output = Whenever.cron \
128
+ <<-file
129
+ set :job_template, nil
130
+ set :path, '/your/path'
131
+ every :daily do
132
+ rake "blah:blah"
133
+ runner "runner_1"
134
+ command "command_1"
135
+ runner "runner_2"
136
+ command "command_2"
137
+ end
138
+ file
139
+
140
+ assert_match '@daily cd /your/path && RAILS_ENV=production bundle exec rake blah:blah --silent', output
141
+ assert_match %(@daily cd /your/path && script/runner -e production 'runner_1'), output
142
+ assert_match '@daily command_1', output
143
+ assert_match %(@daily cd /your/path && script/runner -e production 'runner_2'), output
144
+ assert_match '@daily command_2', output
186
145
  end
187
-
188
- context "every 5 minutes but but starting at 1" do
189
- setup do
190
- @output = Whenever.cron \
191
- <<-file
192
- set :job_template, nil
193
- every 5.minutes, :at => 1 do
194
- command "blahblah"
195
- end
196
- file
197
- end
198
-
199
- should "output the command using that time" do
200
- assert_match '1,6,11,16,21,26,31,36,41,46,51,56 * * * * blahblah', @output
201
- end
146
+
147
+ test "every 5 minutes but but starting at 1" do
148
+ output = Whenever.cron \
149
+ <<-file
150
+ set :job_template, nil
151
+ every 5.minutes, :at => 1 do
152
+ command "blahblah"
153
+ end
154
+ file
155
+
156
+ assert_match '1,6,11,16,21,26,31,36,41,46,51,56 * * * * blahblah', output
202
157
  end
203
158
 
204
- context "every 4 minutes but starting at 2" do
205
- setup do
206
- @output = Whenever.cron \
207
- <<-file
208
- set :job_template, nil
209
- every 4.minutes, :at => 2 do
210
- command "blahblah"
211
- end
212
- file
213
- end
214
-
215
- should "output the command using that time" do
216
- assert_match '2,6,10,14,18,22,26,30,34,38,42,46,50,54,58 * * * * blahblah', @output
217
- end
159
+ test "every 4 minutes but starting at 2" do
160
+ output = Whenever.cron \
161
+ <<-file
162
+ set :job_template, nil
163
+ every 4.minutes, :at => 2 do
164
+ command "blahblah"
165
+ end
166
+ file
167
+
168
+ assert_match '2,6,10,14,18,22,26,30,34,38,42,46,50,54,58 * * * * blahblah', output
218
169
  end
219
170
 
220
- context "every 3 minutes but starting at 7" do
221
- setup do
222
- @output = Whenever.cron \
223
- <<-file
224
- set :job_template, nil
225
- every 3.minutes, :at => 7 do
226
- command "blahblah"
227
- end
228
- file
229
- end
230
-
231
- should "output the command using that time" do
232
- assert_match '7,10,13,16,19,22,25,28,31,34,37,40,43,46,49,52,55,58 * * * * blahblah', @output
233
- end
171
+ test "every 3 minutes but starting at 7" do
172
+ output = Whenever.cron \
173
+ <<-file
174
+ set :job_template, nil
175
+ every 3.minutes, :at => 7 do
176
+ command "blahblah"
177
+ end
178
+ file
179
+
180
+
181
+ assert_match '7,10,13,16,19,22,25,28,31,34,37,40,43,46,49,52,55,58 * * * * blahblah', output
234
182
  end
235
183
 
236
- context "every 2 minutes but starting at 27" do
237
- setup do
238
- @output = Whenever.cron \
239
- <<-file
240
- set :job_template, nil
241
- every 2.minutes, :at => 27 do
242
- command "blahblah"
243
- end
244
- file
245
- end
246
-
247
- should "output the command using that time" do
248
- assert_match '27,29,31,33,35,37,39,41,43,45,47,49,51,53,55,57,59 * * * * blahblah', @output
249
- end
184
+ test "every 2 minutes but starting at 27" do
185
+ output = Whenever.cron \
186
+ <<-file
187
+ set :job_template, nil
188
+ every 2.minutes, :at => 27 do
189
+ command "blahblah"
190
+ end
191
+ file
192
+
193
+ assert_match '27,29,31,33,35,37,39,41,43,45,47,49,51,53,55,57,59 * * * * blahblah', output
250
194
  end
251
-
252
- context "using raw cron syntax" do
253
- setup do
254
- @output = Whenever.cron \
255
- <<-file
256
- set :job_template, nil
257
- every '0 0 27,31 * *' do
258
- command "blahblah"
259
- end
260
- file
261
- end
262
-
263
- should "output the command using the same cron syntax" do
264
- assert_match '0 0 27,31 * * blahblah', @output
265
- end
195
+
196
+ test "using raw cron syntax" do
197
+ output = Whenever.cron \
198
+ <<-file
199
+ set :job_template, nil
200
+ every '0 0 27,31 * *' do
201
+ command "blahblah"
202
+ end
203
+ file
204
+
205
+ assert_match '0 0 27,31 * * blahblah', output
266
206
  end
267
-
268
207
  end