resque_unit 0.4.8 → 1.0.0.beta.2

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.
@@ -1,94 +1,94 @@
1
1
  require 'test_helper'
2
2
 
3
- class ResqueUnitTest < Test::Unit::TestCase
3
+ describe ResqueUnit do
4
4
 
5
- def setup
5
+ before do
6
6
  # should probably happen automatically, but I haven't thought of a
7
7
  # good way to hook setup() yet.
8
8
  Resque.reset!
9
9
  end
10
10
 
11
- context "A task that schedules a resque job implementing self.queue" do
12
- setup { Resque.enqueue(MediumPriorityJob) }
13
- should "pass the assert_queued(job) assertion" do
11
+ describe "A task that schedules a resque job implementing self.queue" do
12
+ before { Resque.enqueue(MediumPriorityJob) }
13
+ it "passes the assert_queued(job) assertion" do
14
14
  assert_queued(MediumPriorityJob)
15
15
  assert_job_created(MediumPriorityJob.queue, MediumPriorityJob)
16
16
  assert_equal 1, Resque.queue(MediumPriorityJob.queue).length
17
17
  end
18
18
  end
19
19
 
20
- context "A task that explicitly is queued to a different queue" do
21
- setup { Resque.enqueue_to(:a_non_class_determined_queue, MediumPriorityJob) }
22
- should "not queue to the class-determined queue" do
20
+ describe "A task that explicitly is queued to a different queue" do
21
+ before { Resque.enqueue_to(:a_non_class_determined_queue, MediumPriorityJob) }
22
+ it "does not queue to the class-determined queue" do
23
23
  assert_equal 0, Resque.queue(MediumPriorityJob.queue).length
24
24
  end
25
- should "queue to the explicly-stated queue" do
25
+ it "queues to the explicly-stated queue" do
26
26
  assert_equal 1, Resque.queue(:a_non_class_determined_queue).length
27
27
  end
28
28
  end
29
29
 
30
- context "A task that spawns multiple jobs on a single queue" do
31
- setup do
30
+ describe "A task that spawns multiple jobs on a single queue" do
31
+ before do
32
32
  3.times {Resque.enqueue(HighPriorityJob)}
33
33
  end
34
34
 
35
- should "allow partial runs with explicit limit" do
35
+ it "allows partial runs with explicit limit" do
36
36
  assert_equal 3, Resque.queue(:high).length, 'failed setup'
37
- Resque.run_for!( :high, 1 )
37
+ Resque.run_for!(:high, 1)
38
38
  assert_equal 2, Resque.queue(:high).length, 'failed to run just single job'
39
39
  end
40
40
 
41
- should "allow full run with too-large explicit limit" do
41
+ it "allows full run with too-large explicit limit" do
42
42
  assert_equal 3, Resque.queue(:high).length, 'failed setup'
43
- Resque.run_for!( :high, 50 )
43
+ Resque.run_for!(:high, 50)
44
44
  assert_equal 0, Resque.queue(:high).length, 'failed to run all jobs'
45
45
  end
46
46
 
47
- should "allow full run with implicit limit" do
47
+ it "allows full run with implicit limit" do
48
48
  assert_equal 3, Resque.queue(:high).length, 'failed setup'
49
- Resque.run_for!( :high )
49
+ Resque.run_for!(:high)
50
50
  assert_equal 0, Resque.queue(:high).length, 'failed to run all jobs'
51
51
  end
52
52
  end
53
53
 
54
- context "A task that schedules a resque job" do
55
- setup do
54
+ describe "A task that schedules a resque job" do
55
+ before do
56
56
  @returned = Resque.enqueue(LowPriorityJob)
57
57
  end
58
58
 
59
- should 'return a value that evaluates to true' do
59
+ it 'returns a value that evaluates to true' do
60
60
  assert @returned
61
61
  end
62
62
 
63
- should "pass the assert_queued(job) assertion" do
63
+ it "passes the assert_queued(job) assertion" do
64
64
  assert_queued(LowPriorityJob)
65
65
  end
66
66
 
67
- should "fail the assert_not_queued(job) assertion" do
68
- assert_raise Test::Unit::AssertionFailedError do
67
+ it "fails the assert_not_queued(job) assertion" do
68
+ assert_raises Minitest::Assertion do
69
69
  assert_not_queued(LowPriorityJob)
70
70
  end
71
71
  end
72
72
 
73
- should "should be size 1" do
73
+ it "has 1 job in the queue" do
74
74
  assert_equal 1, Resque.size(:low)
75
75
  end
76
76
 
77
- context ", when Resque.run! is called," do
78
- setup do
77
+ describe ", when Resque.run! is called," do
78
+ before do
79
79
  assert !LowPriorityJob.run?, "The job should not have been run yet"
80
80
  Resque.run!
81
81
  end
82
82
 
83
- teardown do
83
+ after do
84
84
  LowPriorityJob.run = false
85
85
  end
86
86
 
87
- should "run the job" do
87
+ it "runs the job" do
88
88
  assert LowPriorityJob.run?, "The job should have run"
89
89
  end
90
90
 
91
- should "clear the job from the queue" do
91
+ it "clears the job from the queue" do
92
92
  assert_not_queued(LowPriorityJob)
93
93
  end
94
94
  end
@@ -96,32 +96,24 @@ class ResqueUnitTest < Test::Unit::TestCase
96
96
  # assert number of jobs?
97
97
  end
98
98
 
99
- context "A task that schedules a resque job with hooks" do
100
- setup do
101
- Resque.enable_hooks!
102
- end
103
-
104
- teardown do
105
- Resque.disable_hooks!
106
- end
107
-
108
- context "before, around, after, failure, after_enqueue" do
109
- setup do
99
+ describe "A task that schedules a resque job with hooks" do
100
+ describe "before, around, after, failure, after_enqueue" do
101
+ before do
110
102
  JobWithHooks.clear_markers
111
103
  Resque.enqueue(JobWithHooks)
112
104
  end
113
105
 
114
- should "have run the after_enqueue hook" do
106
+ it "ran the after_enqueue hook" do
115
107
  assert_queued(JobWithHooks)
116
108
  assert(JobWithHooks.markers[:after_enqueue], 'no after_queue marker set')
117
109
  end
118
110
 
119
- should "have run the before_enqueue hook" do
111
+ it "ran the before_enqueue hook" do
120
112
  assert(JobWithHooks.markers[:before_enqueue], 'no before_queue marker set')
121
113
  assert_queued(JobWithHooks)
122
114
  end
123
115
 
124
- should "run the before and after hooks during a run" do
116
+ it "ran the before and after hooks during a run" do
125
117
  Resque.run!
126
118
  assert(JobWithHooks.markers[:before], 'no before marker set')
127
119
  assert(JobWithHooks.markers[:around], 'no around marker set')
@@ -129,9 +121,9 @@ class ResqueUnitTest < Test::Unit::TestCase
129
121
  assert(!JobWithHooks.markers[:failed], 'failed marker set, and it should not')
130
122
  end
131
123
 
132
- should "run the before and failed hooks during a run" do
124
+ it "ran the before and failed hooks during a run" do
133
125
  JobWithHooks.make_it_fail do
134
- assert_raise(RuntimeError) do
126
+ assert_raises(RuntimeError) do
135
127
  Resque.run!
136
128
  assert(JobWithHooks.markers[:before], 'no before marker set')
137
129
  assert(JobWithHooks.markers[:around], 'no around marker set')
@@ -141,7 +133,7 @@ class ResqueUnitTest < Test::Unit::TestCase
141
133
  end
142
134
  end
143
135
 
144
- should "not call perform if the around hook raised Resque::Job::DontPerform" do
136
+ it "does not call perform if the around hook raised Resque::Job::DontPerform" do
145
137
  JobWithHooks.make_it_dont_perform do
146
138
  Resque.run!
147
139
  assert(JobWithHooks.markers[:before], 'no before marker set')
@@ -152,83 +144,83 @@ class ResqueUnitTest < Test::Unit::TestCase
152
144
  end
153
145
  end
154
146
 
155
- context "but without before" do
156
- setup do
147
+ describe "but without before" do
148
+ before do
157
149
  JobWithHooksWithoutBefore.clear_markers
158
150
  Resque.enqueue(JobWithHooksWithoutBefore)
159
151
  end
160
152
 
161
- should "not run before hooks during a run" do
153
+ it "does not run before hooks during a run" do
162
154
  Resque.run!
163
155
  assert(!JobWithHooksWithoutBefore.markers[:before], 'before marker set, and it should not')
164
156
  end
165
157
  end
166
158
 
167
- context "when before_enqueue returns false" do
168
- setup do
159
+ describe "when before_enqueue returns false" do
160
+ before do
169
161
  JobWithHooksBeforeBlocks.clear_markers
170
162
  end
171
163
 
172
- should "not queue" do
164
+ it "does not queue" do
173
165
  Resque.enqueue JobWithHooksBeforeBlocks
174
166
  assert_not_queued JobWithHooksBeforeBlocks
175
167
  end
176
168
 
177
169
  end
178
170
 
179
- context "but without around" do
180
- setup do
171
+ describe "but without around" do
172
+ before do
181
173
  JobWithHooksWithoutAround.clear_markers
182
174
  Resque.enqueue(JobWithHooksWithoutAround)
183
175
  end
184
176
 
185
- should "not run around hooks during a run" do
177
+ it "does not run around hooks during a run" do
186
178
  Resque.run!
187
179
  assert(!JobWithHooksWithoutAround.markers[:around], 'around marker set, and it should not')
188
180
  end
189
181
  end
190
182
  end
191
183
 
192
- context "Block assertions" do
193
- should "pass the assert_queued(job) assertion when queued in block" do
184
+ describe "Block assertions" do
185
+ it "passes the assert_queued(job) assertion when queued in block" do
194
186
  assert_queues(HighPriorityJob) do
195
187
  Resque.enqueue(HighPriorityJob)
196
188
  end
197
189
  end
198
190
 
199
- should "pass the assert_queued(job) assertion when queued in block and outside" do
191
+ it "passes the assert_queued(job) assertion when queued in block and outside" do
200
192
  Resque.enqueue(HighPriorityJob)
201
193
  assert_queues(HighPriorityJob) do
202
194
  Resque.enqueue(HighPriorityJob)
203
195
  end
204
196
  end
205
197
 
206
- should "fail the assert_queued(job) assertion when not queued in block but outside" do
198
+ it "fails the assert_queued(job) assertion when not queued in block but outside" do
207
199
  Resque.enqueue(LowPriorityJob)
208
- assert_raise Test::Unit::AssertionFailedError do
200
+ assert_raises Minitest::Assertion do
209
201
  assert_queues(LowPriorityJob) do
210
202
  # Nothing.
211
203
  end
212
204
  end
213
205
  end
214
206
 
215
- should "pass the assert_not_queued(job) assertion when not queued in block" do
207
+ it "passes the assert_not_queued(job) assertion when not queued in block" do
216
208
  Resque.enqueue(LowPriorityJob)
217
209
  assert_not_queued(LowPriorityJob) do
218
210
  # Nothing.
219
211
  end
220
212
  end
221
213
 
222
- should "fail the assert_not_queued(job) assertion when not queued in block" do
223
- assert_raise Test::Unit::AssertionFailedError do
214
+ it "fails the assert_not_queued(job) assertion when not queued in block" do
215
+ assert_raises Minitest::Assertion do
224
216
  assert_not_queued(LowPriorityJob) do
225
217
  Resque.enqueue(LowPriorityJob)
226
218
  end
227
219
  end
228
220
  end
229
221
 
230
- should "fail the assert_not_queued(job) assertion when queued and not in block" do
231
- assert_raise Test::Unit::AssertionFailedError do
222
+ it "fails the assert_not_queued(job) assertion when queued and not in block" do
223
+ assert_raises Minitest::Assertion do
232
224
  Resque.enqueue(LowPriorityJob)
233
225
  assert_not_queued(LowPriorityJob) do
234
226
  Resque.enqueue(LowPriorityJob)
@@ -236,15 +228,15 @@ class ResqueUnitTest < Test::Unit::TestCase
236
228
  end
237
229
  end
238
230
 
239
- should "pass the assert_nothing_queued assertion when nothing queued in block" do
231
+ it "passes the assert_nothing_queued assertion when nothing queued in block" do
240
232
  Resque.enqueue(LowPriorityJob)
241
233
  assert_nothing_queued do
242
234
  # Nothing.
243
235
  end
244
236
  end
245
237
 
246
- should "fail the assert_nothing_queued assertion when queued in block" do
247
- assert_raise Test::Unit::AssertionFailedError do
238
+ it "fails the assert_nothing_queued assertion when queued in block" do
239
+ assert_raises Minitest::Assertion do
248
240
  assert_nothing_queued do
249
241
  Resque.enqueue(LowPriorityJob)
250
242
  end
@@ -252,127 +244,127 @@ class ResqueUnitTest < Test::Unit::TestCase
252
244
  end
253
245
  end
254
246
 
255
- context "An empty queue" do
256
- should "pass the assert_not_queued(job) assertion" do
247
+ describe "An empty queue" do
248
+ it "passes the assert_not_queued(job) assertion" do
257
249
  assert_not_queued(LowPriorityJob)
258
250
  end
259
251
 
260
- should "fail the assert_queued(job) assertion" do
261
- assert_raise Test::Unit::AssertionFailedError do
252
+ it "fails the assert_queued(job) assertion" do
253
+ assert_raises Minitest::Assertion do
262
254
  assert_queued(LowPriorityJob)
263
255
  end
264
256
  end
265
257
 
266
- should "be size 0 when empty" do
258
+ it "is size 0 when empty" do
267
259
  assert_equal 0, Resque.size(:low)
268
260
  end
269
261
  end
270
262
 
271
- context "A task that schedules a resque job with arguments" do
272
- setup do
263
+ describe "A task that schedules a resque job with arguments" do
264
+ before do
273
265
  Resque.enqueue(JobWithArguments, 1, :test, {:symbol => :symbol})
274
266
  end
275
267
 
276
- should "pass the assert_queued(job, *args) assertion if the args match and sees enqueued symbols as strings" do
268
+ it "passes the assert_queued(job, *args) assertion if the args match and sees enqueued symbols as strings" do
277
269
  assert_queued(JobWithArguments, [1, "test", {"symbol"=>"symbol"}])
278
270
  end
279
271
 
280
- should "pass the assert_queued(job, *args) assertion if the args match using symbols" do
272
+ it "passes the assert_queued(job, *args) assertion if the args match using symbols" do
281
273
  assert_queued(JobWithArguments, [1, :test, {:symbol => :symbol}])
282
274
  end
283
275
 
284
- should "pass the assert_queued(job) assertion with no args passed" do
276
+ it "passes the assert_queued(job) assertion with no args passed" do
285
277
  assert_queued(JobWithArguments)
286
278
  end
287
279
 
288
- should "fail the assert_queued(job) assertion if the args don't match" do
289
- assert_raise Test::Unit::AssertionFailedError do
280
+ it "fails the assert_queued(job) assertion if the args don't match" do
281
+ assert_raises Minitest::Assertion do
290
282
  assert_queued(JobWithArguments, [2, "test"])
291
283
  end
292
284
  end
293
285
 
294
- should "pass the assert_not_queued(job) assertion if the args don't match" do
286
+ it "passes the assert_not_queued(job) assertion if the args don't match" do
295
287
  assert_not_queued(JobWithArguments, [2, "test"])
296
288
  end
297
289
 
298
- should "fail the assert_not_queued(job) assertion if the args match" do
299
- assert_raise Test::Unit::AssertionFailedError do
290
+ it "fails the assert_not_queued(job) assertion if the args match" do
291
+ assert_raises Minitest::Assertion do
300
292
  assert_not_queued(JobWithArguments, [1, "test", {"symbol"=>"symbol"}])
301
293
  end
302
294
  end
303
295
  end
304
296
 
305
- context "A job that schedules a new resque job" do
306
- setup do
297
+ describe "A job that schedules a new resque job" do
298
+ before do
307
299
  Resque.enqueue(JobThatCreatesANewJob)
308
300
  end
309
301
 
310
- should "pass the assert_queued(job) assertion" do
302
+ it "passes the assert_queued(job) assertion" do
311
303
  assert_queued(JobThatCreatesANewJob)
312
304
  end
313
305
 
314
- should "fail the assert_not_queued(job) assertion" do
315
- assert_raise Test::Unit::AssertionFailedError do
306
+ it "fails the assert_not_queued(job) assertion" do
307
+ assert_raises Minitest::Assertion do
316
308
  assert_not_queued(JobThatCreatesANewJob)
317
309
  end
318
310
  end
319
311
 
320
- should "pass the assert_not_queued(LowPriorityJob) assertion" do
312
+ it "passes the assert_not_queued(LowPriorityJob) assertion" do
321
313
  assert_not_queued(LowPriorityJob)
322
314
  end
323
315
 
324
- context ", when Resque.run! is called," do
325
- setup do
316
+ describe ", when Resque.run! is called," do
317
+ before do
326
318
  Resque.run!
327
319
  end
328
320
 
329
- should "clear the job from the queue" do
321
+ it "clears the job from the queue" do
330
322
  assert_not_queued(JobThatCreatesANewJob)
331
323
  end
332
324
 
333
- should "add a LowPriorityJob" do
325
+ it "adds a LowPriorityJob" do
334
326
  assert_queued(LowPriorityJob)
335
327
  end
336
328
  end
337
329
 
338
- context ", when Resque.full_run!" do
339
- setup do
340
- assert !LowPriorityJob.run?, "The job should not have been run yet, did you call 'LowPriorityJob.run = false' in teardowns of other tests?"
330
+ describe ", when Resque.full_run!" do
331
+ before do
332
+ assert !LowPriorityJob.run?, "The job should not have run yet, did you call 'LowPriorityJob.run = false' in teardowns of other tests?"
341
333
  Resque.full_run!
342
334
  end
343
335
 
344
- teardown do
336
+ after do
345
337
  LowPriorityJob.run = false
346
338
  end
347
339
 
348
- should "clear the jobs from the queue" do
340
+ it "clears the jobs from the queue" do
349
341
  assert_not_queued(JobThatCreatesANewJob)
350
342
  assert_not_queued(LowPriorityJob)
351
343
  end
352
344
 
353
- should "run the new resque jobs" do
345
+ it "runs the new resque jobs" do
354
346
  assert LowPriorityJob.run?, "LowPriorityJob should have been run"
355
347
  end
356
348
  end
357
349
  end
358
350
 
359
- context "A task in a different queue" do
360
- setup do
351
+ describe "A task in a different queue" do
352
+ before do
361
353
  Resque.enqueue(LowPriorityJob)
362
354
  Resque.enqueue(HighPriorityJob)
363
355
  end
364
356
 
365
- should "add a LowPriorityJob" do
357
+ it "adds a LowPriorityJob" do
366
358
  assert_queued(LowPriorityJob)
367
359
  end
368
360
 
369
- should "add a HighPriorityJob" do
361
+ it "adds a HighPriorityJob" do
370
362
  assert_queued(HighPriorityJob)
371
363
  end
372
364
 
373
- context ", when Resque.run_for! is called," do
374
- should "run only tasks in the high priority queue" do
375
- Resque.run_for!(Resque.queue_for(HighPriorityJob))
365
+ describe ", when Resque.run_for! is called," do
366
+ it "runs only tasks in the high priority queue" do
367
+ Resque.run_for!(Resque.queue_from_class(HighPriorityJob))
376
368
 
377
369
  assert_queued(LowPriorityJob)
378
370
  assert_not_queued(HighPriorityJob)
@@ -380,80 +372,71 @@ class ResqueUnitTest < Test::Unit::TestCase
380
372
  end
381
373
  end
382
374
 
383
- context "An assertion message" do
384
- context "of assert_queued" do
385
- should "include job class and queue content" do
375
+ describe "An assertion message" do
376
+ describe "of assert_queued" do
377
+ it "includes job class and queue content" do
386
378
  begin
387
379
  assert_not_queued(LowPriorityJob)
388
- rescue Test::Unit::AssertionFailedError => error
380
+ rescue Minitest::Assertion => error
389
381
  assert_equal "LowPriorityJob should have been queued in low: [].", error.message
390
382
  end
391
383
  end
392
384
 
393
- should "include job arguments if provided" do
385
+ it "includes job arguments if provided" do
394
386
  begin
395
387
  assert_not_queued(JobWithArguments, [1, "test"])
396
- rescue Test::Unit::AssertionFailedError => error
388
+ rescue Minitest::Assertion => error
397
389
  assert_equal "JobWithArguments with [1, \"test\"] should have been queued in medium: [].", error.message
398
390
  end
399
391
  end
400
392
  end
401
393
 
402
- context "of assert_not_queued" do
403
- should "include job class and queue content" do
394
+ describe "of assert_not_queued" do
395
+ it "includes job class and queue content" do
404
396
  begin
405
397
  Resque.enqueue(LowPriorityJob)
406
398
  assert_not_queued(LowPriorityJob)
407
- rescue Test::Unit::AssertionFailedError => error
408
- assert_equal "LowPriorityJob should not have been queued in low.", error.message
399
+ rescue Minitest::Assertion => error
400
+ assert_equal "LowPriorityJob should not have been queued in low.", error.message
409
401
  end
410
402
  end
411
403
 
412
- should "include job arguments if provided" do
404
+ it "includes job arguments if provided" do
413
405
  begin
414
406
  Resque.enqueue(JobWithArguments, 1, "test")
415
407
  assert_not_queued(JobWithArguments, [1, "test"])
416
- rescue Test::Unit::AssertionFailedError => error
408
+ rescue Minitest::Assertion => error
417
409
  assert_equal "JobWithArguments with [1, \"test\"] should not have been queued in medium.", error.message
418
410
  end
419
411
  end
420
412
  end
421
413
 
422
- context "of assert_nothing_queued" do
423
- should "include diff" do
414
+ describe "of assert_nothing_queued" do
415
+ it "includes diff" do
424
416
  begin
425
417
  Resque.reset!
426
418
  assert_nothing_queued do
427
419
  Resque.enqueue(LowPriorityJob)
428
420
  end
429
- rescue Test::Unit::AssertionFailedError => error
430
- assert_equal "No jobs should have been queued.\n<0> expected but was\n<1>.", error.message
421
+ rescue Minitest::Assertion => error
422
+ assert_equal "No jobs should have been queued.\nExpected: 0\n Actual: 1", error.message
431
423
  end
432
424
  end
433
425
  end
434
426
  end
435
427
 
436
- context "A job that does not specify a queue" do
437
- should "receive Resque::NoQueueError" do
438
- assert_raise(Resque::NoQueueError) do
428
+ describe "A job that does not specify a queue" do
429
+ it "receives Resque::NoQueueError" do
430
+ assert_raises(Resque::NoQueueError) do
439
431
  Resque.enqueue(JobThatDoesNotSpecifyAQueue)
440
432
  end
441
433
  end
442
434
  end
443
435
 
444
- context "A job that is created using Resque::Job.create" do
445
- should "be queued" do
446
- assert_nothing_raised do
447
- Resque::Job.create(:my_custom_queue, "LowPriorityJob", "arg1", "arg2")
448
- assert_job_created(:my_custom_queue, LowPriorityJob, ["arg1", "arg2"])
449
- end
450
- end
451
-
452
- should "queue a job with a dasherized name" do
453
- assert_nothing_raised do
454
- Resque::Job.create(:my_custom_queue, "low-priority-job", "arg1", "arg2")
455
- assert_job_created(:my_custom_queue, LowPriorityJob, ["arg1", "arg2"])
456
- end
436
+ describe "A job that is created using Resque::Job.create" do
437
+ it "is queued" do
438
+ Resque::Job.create(:my_custom_queue, "LowPriorityJob", "arg1", "arg2")
439
+ assert_job_created(:my_custom_queue, LowPriorityJob, ["arg1", "arg2"])
457
440
  end
458
441
  end
459
442
 
data/test/test_helper.rb CHANGED
@@ -1,9 +1,7 @@
1
1
  require 'rubygems'
2
- require 'shoulda'
2
+ require 'minitest/spec'
3
3
  require 'resque_unit'
4
+ require 'resque_unit_scheduler'
4
5
  require 'sample_jobs'
5
-
6
- # Fix shoulda under 1.9.2. See https://github.com/thoughtbot/shoulda/issues/issue/117
7
- unless defined?(Test::Unit::AssertionFailedError)
8
- Test::Unit::AssertionFailedError = MiniTest::Assertion
9
- end
6
+ require 'minitest/autorun'
7
+ require 'pry-byebug'