1
1
require 'test_helper'
2
2
3
- context "Resque::Job before_perform" do
3
+ describe "Resque::Job before_perform" do
4
4
include PerformJob
5
5
6
6
class ::BeforePerformJob
@@ -13,7 +13,7 @@ def self.perform(history)
13
13
end
14
14
end
15
15
16
- test "it runs before_perform before perform" do
16
+ it "it runs before_perform before perform" do
17
17
result = perform_job ( BeforePerformJob , history = [ ] )
18
18
assert_equal true , result , "perform returned true"
19
19
assert_equal history , [ :before_perform , :perform ]
@@ -29,7 +29,7 @@ def self.perform(history)
29
29
end
30
30
end
31
31
32
- test "raises an error and does not perform if before_perform fails" do
32
+ it "raises an error and does not perform if before_perform fails" do
33
33
history = [ ]
34
34
assert_raises StandardError do
35
35
perform_job ( BeforePerformJobFails , history )
@@ -47,14 +47,14 @@ def self.perform(history)
47
47
end
48
48
end
49
49
50
- test "does not perform if before_perform raises Resque::Job::DontPerform" do
50
+ it "does not perform if before_perform raises Resque::Job::DontPerform" do
51
51
result = perform_job ( BeforePerformJobAborts , history = [ ] )
52
52
assert_equal false , result , "perform returned false"
53
53
assert_equal history , [ :before_perform ] , "Only before_perform was run"
54
54
end
55
55
end
56
56
57
- context "Resque::Job after_perform" do
57
+ describe "Resque::Job after_perform" do
58
58
include PerformJob
59
59
60
60
class ::AfterPerformJob
@@ -66,7 +66,7 @@ def self.after_perform_record_history(history)
66
66
end
67
67
end
68
68
69
- test "it runs after_perform after perform" do
69
+ it "it runs after_perform after perform" do
70
70
result = perform_job ( AfterPerformJob , history = [ ] )
71
71
assert_equal true , result , "perform returned true"
72
72
assert_equal history , [ :perform , :after_perform ]
@@ -82,7 +82,7 @@ def self.after_perform_fail_job(history)
82
82
end
83
83
end
84
84
85
- test "raises an error but has already performed if after_perform fails" do
85
+ it "raises an error but has already performed if after_perform fails" do
86
86
history = [ ]
87
87
assert_raises StandardError do
88
88
perform_job ( AfterPerformJobFails , history )
@@ -91,7 +91,7 @@ def self.after_perform_fail_job(history)
91
91
end
92
92
end
93
93
94
- context "Resque::Job around_perform" do
94
+ describe "Resque::Job around_perform" do
95
95
include PerformJob
96
96
97
97
class ::AroundPerformJob
@@ -105,7 +105,7 @@ def self.around_perform_record_history(history)
105
105
end
106
106
end
107
107
108
- test "it runs around_perform then yields in order to perform" do
108
+ it "it runs around_perform then yields in order to perform" do
109
109
result = perform_job ( AroundPerformJob , history = [ ] )
110
110
assert_equal true , result , "perform returned true"
111
111
assert_equal history , [ :start_around_perform , :perform , :finish_around_perform ]
@@ -123,7 +123,7 @@ def self.around_perform_fail(history)
123
123
end
124
124
end
125
125
126
- test "raises an error and does not perform if around_perform fails before yielding" do
126
+ it "raises an error and does not perform if around_perform fails before yielding" do
127
127
history = [ ]
128
128
assert_raises StandardError do
129
129
perform_job ( AroundPerformJobFailsBeforePerforming , history )
@@ -147,7 +147,7 @@ def self.around_perform_fail_in_yield(history)
147
147
end
148
148
end
149
149
150
- test "raises an error but may handle exceptions if perform fails" do
150
+ it "raises an error but may handle exceptions if perform fails" do
151
151
history = [ ]
152
152
assert_raises StandardError do
153
153
perform_job ( AroundPerformJobFailsWhilePerforming , history )
@@ -165,15 +165,15 @@ def self.around_perform_dont_yield(history)
165
165
end
166
166
end
167
167
168
- test "around_perform is not required to yield" do
168
+ it "around_perform is not required to yield" do
169
169
history = [ ]
170
170
result = perform_job ( AroundPerformJobDoesNotHaveToYield , history )
171
171
assert_equal false , result , "perform returns false"
172
172
assert_equal history , [ :start_around_perform , :finish_around_perform ] , "perform was not run"
173
173
end
174
174
end
175
175
176
- context "Resque::Job on_failure" do
176
+ describe "Resque::Job on_failure" do
177
177
include PerformJob
178
178
179
179
class ::FailureJobThatDoesNotFail
@@ -185,7 +185,7 @@ def self.on_failure_record_failure(exception, history)
185
185
end
186
186
end
187
187
188
- test "it does not call on_failure if no failures occur" do
188
+ it "it does not call on_failure if no failures occur" do
189
189
result = perform_job ( FailureJobThatDoesNotFail , history = [ ] )
190
190
assert_equal true , result , "perform returned true"
191
191
assert_equal history , [ :perform ]
@@ -201,7 +201,7 @@ def self.on_failure_record_failure(exception, history)
201
201
end
202
202
end
203
203
204
- test "it calls on_failure with the exception and then re-raises the exception" do
204
+ it "it calls on_failure with the exception and then re-raises the exception" do
205
205
history = [ ]
206
206
assert_raises StandardError do
207
207
perform_job ( FailureJobThatFails , history )
@@ -219,7 +219,7 @@ def self.on_failure_record_failure(exception, history)
219
219
end
220
220
end
221
221
222
- test "it calls on_failure even with bad exceptions" do
222
+ it "it calls on_failure even with bad exceptions" do
223
223
history = [ ]
224
224
assert_raises SyntaxError do
225
225
perform_job ( FailureJobThatFailsBadly , history )
@@ -228,7 +228,7 @@ def self.on_failure_record_failure(exception, history)
228
228
end
229
229
end
230
230
231
- context "Resque::Job after_enqueue" do
231
+ describe "Resque::Job after_enqueue" do
232
232
include PerformJob
233
233
234
234
class ::AfterEnqueueJob
@@ -241,7 +241,7 @@ def self.perform(history)
241
241
end
242
242
end
243
243
244
- test "the after enqueue hook should run" do
244
+ it "the after enqueue hook should run" do
245
245
history = [ ]
246
246
@worker = Resque ::Worker . new ( :jobs )
247
247
Resque . enqueue ( AfterEnqueueJob , history )
@@ -251,7 +251,7 @@ def self.perform(history)
251
251
end
252
252
253
253
254
- context "Resque::Job before_enqueue" do
254
+ describe "Resque::Job before_enqueue" do
255
255
include PerformJob
256
256
257
257
class ::BeforeEnqueueJob
@@ -274,23 +274,23 @@ def self.perform(history)
274
274
end
275
275
end
276
276
277
- test "the before enqueue hook should run" do
277
+ it "the before enqueue hook should run" do
278
278
history = [ ]
279
279
@worker = Resque ::Worker . new ( :jobs )
280
280
assert Resque . enqueue ( BeforeEnqueueJob , history )
281
281
@worker . work ( 0 )
282
282
assert_equal history , [ :before_enqueue ] , "before_enqueue was not run"
283
283
end
284
284
285
- test "a before enqueue hook that returns false should prevent the job from getting queued" do
285
+ it "a before enqueue hook that returns false should prevent the job from getting queued" do
286
286
history = [ ]
287
287
@worker = Resque ::Worker . new ( :jobs )
288
288
assert_nil Resque . enqueue ( BeforeEnqueueJobAbort , history )
289
289
assert_equal 0 , Resque . size ( :jobs )
290
290
end
291
291
end
292
292
293
- context "Resque::Job after_dequeue" do
293
+ describe "Resque::Job after_dequeue" do
294
294
include PerformJob
295
295
296
296
class ::AfterDequeueJob
@@ -303,7 +303,7 @@ def self.perform(history)
303
303
end
304
304
end
305
305
306
- test "the after dequeue hook should run" do
306
+ it "the after dequeue hook should run" do
307
307
history = [ ]
308
308
@worker = Resque ::Worker . new ( :jobs )
309
309
Resque . dequeue ( AfterDequeueJob , history )
@@ -313,7 +313,7 @@ def self.perform(history)
313
313
end
314
314
315
315
316
- context "Resque::Job before_dequeue" do
316
+ describe "Resque::Job before_dequeue" do
317
317
include PerformJob
318
318
319
319
class ::BeforeDequeueJob
@@ -336,21 +336,21 @@ def self.perform(history)
336
336
end
337
337
end
338
338
339
- test "the before dequeue hook should run" do
339
+ it "the before dequeue hook should run" do
340
340
history = [ ]
341
341
@worker = Resque ::Worker . new ( :jobs )
342
342
Resque . dequeue ( BeforeDequeueJob , history )
343
343
@worker . work ( 0 )
344
344
assert_equal history , [ :before_dequeue ] , "before_dequeue was not run"
345
345
end
346
346
347
- test "a before dequeue hook that returns false should prevent the job from getting dequeued" do
347
+ it "a before dequeue hook that returns false should prevent the job from getting dequeued" do
348
348
history = [ ]
349
349
assert_equal nil , Resque . dequeue ( BeforeDequeueJobAbort , history )
350
350
end
351
351
end
352
352
353
- context "Resque::Job all hooks" do
353
+ describe "Resque::Job all hooks" do
354
354
include PerformJob
355
355
356
356
class ::VeryHookyJob
@@ -373,7 +373,7 @@ def self.on_failure_record_history(exception, history)
373
373
end
374
374
end
375
375
376
- test "the complete hook order" do
376
+ it "the complete hook order" do
377
377
result = perform_job ( VeryHookyJob , history = [ ] )
378
378
assert_equal true , result , "perform returned true"
379
379
assert_equal history , [
@@ -406,7 +406,7 @@ def self.on_failure_record_history(exception, history)
406
406
end
407
407
end
408
408
409
- test "the complete hook order with a failure at the last minute" do
409
+ it "the complete hook order with a failure at the last minute" do
410
410
history = [ ]
411
411
assert_raises StandardError do
412
412
perform_job ( VeryHookyJobThatFails , history )
0 commit comments