resque_spec 0.15.0 → 0.18.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 38399f5b3aacdb7864ae1101449c6503fa67227a032ea86a7e3447410cedbbf5
4
+ data.tar.gz: 348ebcfe24c589c9c02d956d5f7e4e654384ff7d5f76cd51f4e3c98515863b33
5
+ SHA512:
6
+ metadata.gz: '0609f884100cc19e2862500a76cd7794f78ae3ec4e663ae3b0854fec63ee5e369b5571ac273130ece8f2e556df0a831f80bdb5f0517d2b488dd46ad75bc65170'
7
+ data.tar.gz: 6a204ca5dd6089f424ef34acbd52ac6bf5e80722bcc5d4f88ec85b64c8649f3a4d994dac578cd7779bc1a31df21436890c916e6fa9a4d3de50e7321dc0a3d16f
data/README.md CHANGED
@@ -10,9 +10,6 @@ on
10
10
 
11
11
  ResqueSpec will also fire Resque hooks if you are using them. See below.
12
12
 
13
- The current version works with `Resque >~ v1.19` and up and `RSpec >= v2.5.0`
14
- (including the RSpec 3 beta).
15
-
16
13
  Install
17
14
  -------
18
15
 
@@ -21,9 +18,11 @@ using `bundler`? Do the necessary thing for your app's gem management and use
21
18
  `bundler`. `resque_spec` monkey patches `resque` it should only be used with
22
19
  your tests!)
23
20
 
24
- group :test do
25
- gem 'resque_spec'
26
- end
21
+ ```ruby
22
+ group :test do
23
+ gem 'resque_spec'
24
+ end
25
+ ```
27
26
 
28
27
  Cucumber
29
28
  --------
@@ -32,8 +31,9 @@ By default, the above will add the `ResqueSpec` module and make it available in
32
31
  Cucumber. If you want the `with_resque` and `without_resque` helpers, manually
33
32
  require the `resque_spec/cucumber` module:
34
33
 
35
- require 'resque_spec/cucumber'
36
-
34
+ ```ruby
35
+ require 'resque_spec/cucumber'
36
+ ```
37
37
  This can be done in `features/support/env.rb` or in a specific support file
38
38
  such as `features/support/resque.rb`.
39
39
 
@@ -59,64 +59,72 @@ Given this scenario
59
59
 
60
60
  And I write this spec using the `resque_spec` matcher
61
61
 
62
- describe "#recalculate" do
63
- before do
64
- ResqueSpec.reset!
65
- end
66
-
67
- it "adds person.calculate to the Person queue" do
68
- person.recalculate
69
- Person.should have_queued(person.id, :calculate)
70
- end
71
- end
62
+ ```ruby
63
+ describe "#recalculate" do
64
+ before do
65
+ ResqueSpec.reset!
66
+ end
72
67
 
68
+ it "adds person.calculate to the Person queue" do
69
+ person.recalculate
70
+ expect(Person).to have_queued(person.id, :calculate)
71
+ end
72
+ end
73
+ ```
73
74
 
74
75
  And I see that the `have_queued` assertion is asserting that the `Person` queue has a job with arguments `person.id` and `:calculate`
75
76
 
76
77
  And I take note of the `before` block that is calling `reset!` for every spec
77
78
 
78
79
  And I might use the `in` statement to specify the queue:
79
-
80
- describe "#recalculate" do
81
- before do
82
- ResqueSpec.reset!
83
- end
84
-
85
- it "adds person.calculate to the Person queue" do
86
- person.recalculate
87
- Person.should have_queued(person.id, :calculate).in(:people)
88
- end
89
- end
80
+ ```ruby
81
+ describe "#recalculate" do
82
+ before do
83
+ ResqueSpec.reset!
84
+ end
85
+
86
+ it "adds person.calculate to the Person queue" do
87
+ person.recalculate
88
+ expect(Person).to have_queued(person.id, :calculate).in(:people)
89
+ end
90
+ end
91
+ ```
90
92
 
91
93
  And I might write this as a Cucumber step
92
94
 
93
- Then /the (\w?) has (\w?) queued/ do |thing, method|
94
- thing_obj = instance_variable_get("@#{thing}")
95
- thing_obj.class.should have_queued(thing_obj.id, method.to_sym)
96
- end
95
+ ```ruby
96
+ Then /the (\w?) has (\w?) queued/ do |thing, method|
97
+ thing_obj = instance_variable_get("@#{thing}")
98
+ expect(thing_obj.class).to have_queued(thing_obj.id, method.to_sym)
99
+ end
100
+ ```
97
101
 
98
102
  Then I write some code to make it pass:
99
103
 
100
- class Person
101
- @queue = :people
104
+ ```ruby
105
+ class Person
106
+ @queue = :people
102
107
 
103
- def recalculate
104
- Resque.enqueue(Person, id, :calculate)
105
- end
106
- end
108
+ def recalculate
109
+ Resque.enqueue(Person, id, :calculate)
110
+ end
111
+ end
112
+ ```
107
113
 
108
114
  You can check the size of the queue in your specs too.
109
115
 
110
- describe "#recalculate" do
111
- before do
112
- ResqueSpec.reset!
113
- end
116
+ ```ruby
117
+ describe "#recalculate" do
118
+ before do
119
+ ResqueSpec.reset!
120
+ end
114
121
 
115
- it "adds an entry to the Person queue" do
116
- person.recalculate
117
- Person.should have_queue_size_of(1)
118
- end
119
- end
122
+ it "adds an entry to the Person queue" do
123
+ person.recalculate
124
+ expect(Person).to have_queue_size_of(1)
125
+ end
126
+ end
127
+ ```
120
128
 
121
129
  Turning off ResqueSpec and calling directly to Resque
122
130
  -----------------------------------------------------
@@ -125,20 +133,24 @@ Occasionally, you want to run your specs directly against Resque instead of
125
133
  ResqueSpec. For one at a time use, pass a block to the `without_resque_spec`
126
134
  helper:
127
135
 
128
- describe "#recalculate" do
129
- it "recalculates the persons score" do
130
- without_resque_spec do
131
- person.recalculate
132
- end
133
- ... assert recalculation after job done
134
- end
136
+ ```ruby
137
+ describe "#recalculate" do
138
+ it "recalculates the persons score" do
139
+ without_resque_spec do
140
+ person.recalculate
135
141
  end
142
+ ... assert recalculation after job done
143
+ end
144
+ end
145
+ ```
136
146
 
137
147
  Or you can manage when ResqueSpec is disabled by flipping the
138
148
  `ResqueSpec.disable_ext` flag:
139
149
 
140
- # disable ResqueSpec
141
- ResqueSpec.disable_ext = true
150
+ ```ruby
151
+ # disable ResqueSpec
152
+ ResqueSpec.disable_ext = true
153
+ ```
142
154
 
143
155
  You will most likely (but not always, see the Resque docs) need to ensure that
144
156
  you have `redis` running.
@@ -150,39 +162,47 @@ To use with [ResqueMailer](https://github.com/zapnap/resque_mailer) you should
150
162
  have an initializer that does *not* exclude the `test` (or `cucumber`)
151
163
  environment. Your initializer will probably end up looking like:
152
164
 
153
- # config/initializers/resque_mailer.rb
154
- Resque::Mailer.excluded_environments = []
165
+ ```ruby
166
+ # config/initializers/resque_mailer.rb
167
+ Resque::Mailer.excluded_environments = []
168
+ ```
155
169
 
156
170
  If you have a mailer like this:
157
171
 
158
- class ExampleMailer < ActionMailer::Base
159
- include Resque::Mailer
172
+ ```ruby
173
+ class ExampleMailer < ActionMailer::Base
174
+ include Resque::Mailer
160
175
 
161
- def welcome_email(user_id)
162
- end
163
- end
176
+ def welcome_email(user_id)
177
+ end
178
+ end
179
+ ```
164
180
 
165
181
  You can write a spec like this:
166
182
 
167
- describe "#welcome_email" do
168
- before do
169
- ResqueSpec.reset!
170
- Examplemailer.welcome_email(user.id).deliver
171
- end
183
+ ```ruby
184
+ describe "#welcome_email" do
185
+ before do
186
+ ResqueSpec.reset!
187
+ Examplemailer.welcome_email(user.id).deliver
188
+ end
172
189
 
173
- subject { described_class }
174
- it { should have_queue_size_of(1) }
175
- it { should have_queued(:welcome_email, user.id) }
176
- end
190
+ subject { described_class }
191
+ it { should have_queue_size_of(1) }
192
+ it { should have_queued(:welcome_email, [user.id]) }
193
+ end
194
+ ```
177
195
 
178
196
  resque-scheduler with Specs
179
197
  ==========================
180
198
 
181
- To use with resque-scheduler, add this require `require 'resque_spec/scheduler'`
182
-
183
- *n.b.* Yes, you also need to require resque-scheduler, this works (check the docs for other ways):
199
+ Update the Gemfile to enable the `resque-schedular` matchers:
184
200
 
185
- gem "resque-scheduler", :require => "resque_scheduler"
201
+ ```ruby
202
+ group :test do
203
+ gem 'resque_spec', require: 'resque_spec/scheduler'
204
+ end
205
+ ```
186
206
 
187
207
  Given this scenario
188
208
 
@@ -192,98 +212,112 @@ Given this scenario
192
212
 
193
213
  And I write this spec using the `resque_spec` matcher
194
214
 
195
- describe "#recalculate" do
196
- before do
197
- ResqueSpec.reset!
198
- end
215
+ ```ruby
216
+ describe "#recalculate" do
217
+ before do
218
+ ResqueSpec.reset!
219
+ end
199
220
 
200
- it "adds person.calculate to the Person queue" do
201
- person.recalculate
202
- Person.should have_scheduled(person.id, :calculate)
203
- end
204
- end
221
+ it "adds person.calculate to the Person queue" do
222
+ person.recalculate
223
+ expect(Person).to have_scheduled(person.id, :calculate)
224
+ end
225
+ end
226
+ ```
205
227
 
206
228
  And I might use the `at` statement to specify the time:
207
229
 
208
- describe "#recalculate" do
209
- before do
210
- ResqueSpec.reset!
211
- end
230
+ ```ruby
231
+ describe "#recalculate" do
232
+ before do
233
+ ResqueSpec.reset!
234
+ end
212
235
 
213
- it "adds person.calculate to the Person queue" do
214
- person.recalculate
236
+ it "adds person.calculate to the Person queue" do
237
+ person.recalculate
215
238
 
216
- # Is it scheduled to be executed at 2010-02-14 06:00:00 ?
217
- Person.should have_scheduled(person.id, :calculate).at(Time.mktime(2010,2,14,6,0,0))
218
- end
219
- end
239
+ # Is it scheduled to be executed at 2010-02-14 06:00:00 ?
240
+ expect(Person).to have_scheduled(person.id, :calculate).at(Time.mktime(2010,2,14,6,0,0))
241
+ end
242
+ end
243
+ ```
220
244
 
221
245
  And I might use the `in` statement to specify time interval (in seconds):
222
246
 
223
- describe "#recalculate" do
224
- before do
225
- ResqueSpec.reset!
226
- end
247
+ ```ruby
248
+ describe "#recalculate" do
249
+ before do
250
+ ResqueSpec.reset!
251
+ end
227
252
 
228
- it "adds person.calculate to the Person queue" do
229
- person.recalculate
253
+ it "adds person.calculate to the Person queue" do
254
+ person.recalculate
230
255
 
231
- # Is it scheduled to be executed in 5 minutes?
232
- Person.should have_scheduled(person.id, :calculate).in(5 * 60)
233
- end
234
- end
256
+ # Is it scheduled to be executed in 5 minutes?
257
+ expect(Person).to have_scheduled(person.id, :calculate).in(5 * 60)
258
+ end
259
+ end
260
+ ```
235
261
 
236
262
  You can also check the size of the schedule:
237
263
 
238
- describe "#recalculate" do
239
- before do
240
- ResqueSpec.reset!
241
- end
264
+ ```ruby
265
+ describe "#recalculate" do
266
+ before do
267
+ ResqueSpec.reset!
268
+ end
242
269
 
243
- it "adds person.calculate to the Person queue" do
244
- person.recalculate
270
+ it "adds person.calculate to the Person queue" do
271
+ person.recalculate
245
272
 
246
- Person.should have_schedule_size_of(1)
247
- end
248
- end
273
+ expect(Person).to have_schedule_size_of(1)
274
+ end
275
+ end
276
+ ```
249
277
 
250
278
  (And I take note of the `before` block that is calling `reset!` for every spec)
251
279
 
252
280
  You can explicitly specify the queue when using enqueue_at_with_queue and
253
281
  enqueue_in_with_queue:
254
282
 
255
- describe "#recalculate_in_future" do
256
- before do
257
- ResqueSpec.reset!
258
- end
283
+ ```ruby
284
+ describe "#recalculate_in_future" do
285
+ before do
286
+ ResqueSpec.reset!
287
+ end
259
288
 
260
- it "adds person.calculate to the :future queue" do
261
- person.recalculate_in_future
289
+ it "adds person.calculate to the :future queue" do
290
+ person.recalculate_in_future
262
291
 
263
- Person.should have_schedule_size_of(1).queue(:future)
264
- end
265
- end
292
+ Person.should have_schedule_size_of(1).queue(:future)
293
+ end
294
+ end
295
+ ```
266
296
 
267
297
  And I might write this as a Cucumber step
268
298
 
269
- Then /the (\w?) has (\w?) scheduled/ do |thing, method|
270
- thing_obj = instance_variable_get("@#{thing}")
271
- thing_obj.class.should have_scheduled(thing_obj.id, method.to_sym)
272
- end
299
+ ```ruby
300
+ Then /the (\w?) has (\w?) scheduled/ do |thing, method|
301
+ thing_obj = instance_variable_get("@#{thing}")
302
+ expect(thing_obj.class).to have_scheduled(thing_obj.id, method.to_sym)
303
+ end
304
+ ```
273
305
 
274
306
  Then I write some code to make it pass:
275
307
 
276
- class Person
277
- @queue = :people
308
+ ```ruby
309
+ class Person
310
+ @queue = :people
278
311
 
279
- def recalculate
280
- Resque.enqueue_at(Time.now + 3600, Person, id, :calculate)
281
- end
312
+ def recalculate
313
+ Resque.enqueue_at(Time.now + 3600, Person, id, :calculate)
314
+ end
282
315
 
283
- def recalculate_in_future
284
- Resque.enqueue_at_with_queue(:future, Time.now + 3600, Person, id, :calculate)
285
- end
286
- end
316
+ def recalculate_in_future
317
+ Resque.enqueue_at_with_queue(:future, Time.now + 3600, Person, id, :calculate)
318
+ end
319
+ end
320
+ ```
287
321
 
288
322
  Performing Jobs in Specs
289
323
  ========================
@@ -305,27 +339,31 @@ Given this scenario
305
339
 
306
340
  I might write this as a Cucumber step
307
341
 
308
- When /I score/ do
309
- with_resque do
310
- visit game_path
311
- click_link 'Score!'
312
- end
313
- end
342
+ ```ruby
343
+ When /I score/ do
344
+ with_resque do
345
+ visit game_path
346
+ click_link 'Score!'
347
+ end
348
+ end
349
+ ```
314
350
 
315
351
  Or I write this spec using the `with_resque` helper
316
352
 
317
- describe "#score!" do
318
- before do
319
- ResqueSpec.reset!
320
- end
321
-
322
- it "increases the score" do
323
- with_resque do
324
- game.score!
325
- end
326
- game.score.should == 10
327
- end
353
+ ```ruby
354
+ describe "#score!" do
355
+ before do
356
+ ResqueSpec.reset!
357
+ end
358
+
359
+ it "increases the score" do
360
+ with_resque do
361
+ game.score!
328
362
  end
363
+ expect(game.score).to == 10
364
+ end
365
+ end
366
+ ```
329
367
 
330
368
  You can turn this behavior on by setting `ResqueSpec.inline = true`.
331
369
 
@@ -345,9 +383,11 @@ Given this scenario:
345
383
 
346
384
  I might write this as a Cucumber step
347
385
 
348
- When /the (\w+) queue runs/ do |queue_name|
349
- ResqueSpec.perform_all(queue_name)
350
- end
386
+ ```ruby
387
+ When /the (\w+) queue runs/ do |queue_name|
388
+ ResqueSpec.perform_all(queue_name)
389
+ end
390
+ ```
351
391
 
352
392
  Hooks
353
393
  =====
@@ -387,39 +427,45 @@ Follow me on [Github](https://github.com/leshill) and
387
427
  Contributors
388
428
  ============
389
429
 
390
- * Kenneth Kalmer (@kennethkalmer) : rspec dependency fix
391
- * Brian Cardarella (@bcardarella) : fix mutation bug
392
- * Joshua Davey (@joshdavey) : with\_resque helper
393
- * Lar Van Der Jagt (@supaspoida) : with\_resque helper
394
- * Evan Sagge (@evansagge) : Hook in via Job.create, have\_queued.in
395
- * Jon Larkowski (@l4rk) : inline perform
396
- * James Conroy-Finn (@jcf) : spec fix
397
- * Dennis Walters (@ess) : enqueue\_in support
398
- * (@RipTheJacker) : remove\_delayed support
399
- * Kurt Werle (@kwerle) : explicit require spec for v020
400
- * (@dwilkie) : initial before\_enqueue support
401
- * Marcin Balinski (@marcinb) : have\_schedule\_size\_of matcher, schedule matcher at, in
402
- * (@alexeits) : fix matcher in bug with RSpec 2.8.0
403
- * (@ToadJamb) : encode/decode of Resque job arguments
404
- * Mateusz Konikowski (@mkonikowski) : support for anything matcher
405
- * Mathieu Ravaux (@mathieuravaux) : without\_resque\_spec support
406
- * Arjan van der Gaag (@avdgaag) : peek support
407
- * (@dtsiknis) : Updated removed\_delayed
408
- * Li Ellis Gallardo (@lellisga) : fix inline/disable\_ext bug
409
- * Jeff Deville (@jeffdeville) : Resque.size
410
- * Frank Wambutt (@opinel) : Fix DST problem in `have_scheduled`
411
- * Luke Melia (@lukemelia) : Add `times` chained matcher
412
- * Pablo Fernandez (@heelhook) : Add `have_queue_size_of_at_least` and `have_schedule_size_of_at_least` matchers
413
- * (@k1w1) : Add support for enqueue\_at\_with\_queue/enqueue\_in\_with\_queue
414
- * Ozéias Sant'ana (@ozeias) : Update specs to RSpec 2.10
415
- * Yuya Kitajima (@yuyak) : Add ResqueMailer examples to README
416
- * Andrés Bravo (@andresbravog) : Replace `rspec` dependency with explicit dependencies
417
- * Ben Woosley (@Empact) : Loosen rubygems version constraint
418
- * Jeff Dickey (@dickeyxxx) : Remove 2.0 warnings, added Travis
419
- * Earle Clubb (@eclubb) : `be_queued` matcher
420
- * Erkki Eilonen (@erkki) : RSpec 3 support
430
+ * Kenneth Kalmer (@kennethkalmer) : rspec dependency fix
431
+ * Brian Cardarella (@bcardarella) : fix mutation bug
432
+ * Joshua Davey (@joshdavey) : with\_resque helper
433
+ * Lar Van Der Jagt (@supaspoida) : with\_resque helper
434
+ * Evan Sagge (@evansagge) : Hook in via Job.create, have\_queued.in
435
+ * Jon Larkowski (@l4rk) : inline perform
436
+ * James Conroy-Finn (@jcf) : spec fix
437
+ * Dennis Walters (@ess) : enqueue\_in support
438
+ * (@RipTheJacker) : remove\_delayed support
439
+ * Kurt Werle (@kwerle) : explicit require spec for v020
440
+ * (@dwilkie) : initial before\_enqueue support
441
+ * Marcin Balinski (@marcinb) : have\_schedule\_size\_of matcher, schedule matcher at, in
442
+ * (@alexeits) : fix matcher in bug with RSpec 2.8.0
443
+ * (@ToadJamb) : encode/decode of Resque job arguments
444
+ * Mateusz Konikowski (@mkonikowski) : support for anything matcher
445
+ * Mathieu Ravaux (@mathieuravaux) : without\_resque\_spec support
446
+ * Arjan van der Gaag (@avdgaag) : peek support
447
+ * (@dtsiknis) : Updated removed\_delayed
448
+ * Li Ellis Gallardo (@lellisga) : fix inline/disable\_ext bug
449
+ * Jeff Deville (@jeffdeville) : Resque.size
450
+ * Frank Wambutt (@opinel) : Fix DST problem in `have_scheduled`
451
+ * Luke Melia (@lukemelia) : Add `times` chained matcher
452
+ * Pablo Fernandez (@heelhook) : Add `have_queue_size_of_at_least` and `have_schedule_size_of_at_least` matchers
453
+ * (@k1w1) : Add support for enqueue\_at\_with\_queue/enqueue\_in\_with\_queue
454
+ * Ozéias Sant'ana (@ozeias) : Update specs to RSpec 2.10
455
+ * Yuya Kitajima (@yuyak) : Add ResqueMailer examples to README
456
+ * Andrés Bravo (@andresbravog) : Replace `rspec` dependency with explicit dependencies
457
+ * Ben Woosley (@Empact) : Loosen rubygems version constraint
458
+ * Jeff Dickey (@dickeyxxx) : Remove 2.0 warnings, added Travis
459
+ * Earle Clubb (@eclubb) : `be_queued` matcher
460
+ * Erkki Eilonen (@erkki) : RSpec 3 support
461
+ * Gavin Heavyside (@gavinheavyside) : RSpec three warnings
462
+ * Pavel Khrulev (@PaulSchuher) : Resque 2 and RSpec 3 support
463
+ * Ilya Katz (@ilyakatz) : Cleanup README.md for RSpec 3
464
+ * (@addbrick) : Compare times as integers in `have_scheduled` matcher
465
+ * Serious Haircut (@serioushaircut) : Fix ArgumentListMatcher to make it work with any\_args
466
+ * Harry Lascelles (@hlascelles) : Fix error when resque-spec is disabled
421
467
 
422
468
  Copyright
423
469
  =========
424
470
 
425
- Copyright (c) 2010-2014 Les Hill. See LICENSE for details.
471
+ Copyright (c) 2010-2015 Les Hill. See LICENSE for details.
@@ -2,7 +2,18 @@ require 'rspec/core'
2
2
  require 'rspec/expectations'
3
3
  require 'rspec/mocks'
4
4
 
5
+ module ArgsHelper
6
+ private
7
+
8
+ def match_args(expected_args, args)
9
+ arg_list_matcher = RSpec::Mocks::ArgumentListMatcher.new(*expected_args)
10
+ arg_list_matcher.args_match?(*args)
11
+ end
12
+ end
13
+
5
14
  module InQueueHelper
15
+ include ArgsHelper
16
+
6
17
  def self.included(klass)
7
18
  klass.class_eval do
8
19
  attr_accessor :queue_name
@@ -21,7 +32,6 @@ module InQueueHelper
21
32
  ResqueSpec.queue_for(actual)
22
33
  end
23
34
  end
24
-
25
35
  end
26
36
 
27
37
  RSpec::Matchers.define :be_queued do |*expected_args|
@@ -41,7 +51,7 @@ RSpec::Matchers.define :be_queued do |*expected_args|
41
51
  matched = queue(actual).select do |entry|
42
52
  klass = entry.fetch(:class)
43
53
  args = entry.fetch(:args)
44
- klass.to_s == actual.to_s && expected_args == args
54
+ klass.to_s == actual.to_s && match_args(expected_args, args)
45
55
  end
46
56
 
47
57
  if @times
@@ -51,59 +61,22 @@ RSpec::Matchers.define :be_queued do |*expected_args|
51
61
  end
52
62
  end
53
63
 
54
- failure_message_for_should do |actual|
64
+ failure_message do |actual|
55
65
  "expected that #{actual} would be queued with [#{expected_args.join(', ')}]#{@times_info}"
56
66
  end
57
67
 
58
- failure_message_for_should_not do |actual|
68
+ failure_message_when_negated do |actual|
59
69
  "expected that #{actual} would not be queued with [#{expected_args.join(', ')}]#{@times_info}"
60
70
  end
61
71
 
62
72
  description do
63
73
  "be queued with arguments of [#{expected_args.join(', ')}]#{@times_info}"
64
74
  end
65
- end
66
-
67
- RSpec::Matchers.define :have_queued do |*expected_args|
68
- include InQueueHelper
69
-
70
- chain :times do |num_times_queued|
71
- @times = num_times_queued
72
- @times_info = @times == 1 ? ' once' : " #{@times} times"
73
- end
74
-
75
- chain :once do
76
- @times = 1
77
- @times_info = ' once'
78
- end
79
-
80
- match do |actual|
81
- matched = queue(actual).select do |entry|
82
- klass = entry.fetch(:class)
83
- args = entry.fetch(:args)
84
- klass.to_s == actual.to_s && expected_args == args
85
- end
86
-
87
- if @times
88
- matched.size == @times
89
- else
90
- matched.size > 0
91
- end
92
- end
93
-
94
- failure_message_for_should do |actual|
95
- "expected that #{actual} would have [#{expected_args.join(', ')}] queued#{@times_info}"
96
- end
97
-
98
- failure_message_for_should_not do |actual|
99
- "expected that #{actual} would not have [#{expected_args.join(', ')}] queued#{@times_info}"
100
- end
101
75
 
102
- description do
103
- "have queued arguments of [#{expected_args.join(', ')}]#{@times_info}"
104
- end
105
76
  end
106
77
 
78
+ RSpec::Matchers.alias_matcher :have_queued, :be_queued
79
+
107
80
  RSpec::Matchers.define :have_queue_size_of do |size|
108
81
  include InQueueHelper
109
82
 
@@ -111,11 +84,11 @@ RSpec::Matchers.define :have_queue_size_of do |size|
111
84
  queue(actual).size == size
112
85
  end
113
86
 
114
- failure_message_for_should do |actual|
87
+ failure_message do |actual|
115
88
  "expected that #{actual} would have #{size} entries queued, but got #{queue(actual).size} instead"
116
89
  end
117
90
 
118
- failure_message_for_should_not do |actual|
91
+ failure_message_when_negated do |actual|
119
92
  "expected that #{actual} would not have #{size} entries queued, but got #{queue(actual).size} instead"
120
93
  end
121
94
 
@@ -131,11 +104,11 @@ RSpec::Matchers.define :have_queue_size_of_at_least do |size|
131
104
  queue(actual).size >= size
132
105
  end
133
106
 
134
- failure_message_for_should do |actual|
107
+ failure_message do |actual|
135
108
  "expected that #{actual} would have at least #{size} entries queued, but got #{queue(actual).size} instead"
136
109
  end
137
110
 
138
- failure_message_for_should_not do |actual|
111
+ failure_message_when_negated do |actual|
139
112
  "expected that #{actual} would not have at least #{size} entries queued, but got #{queue(actual).size} instead"
140
113
  end
141
114
 
@@ -145,6 +118,8 @@ RSpec::Matchers.define :have_queue_size_of_at_least do |size|
145
118
  end
146
119
 
147
120
  module ScheduleQueueHelper
121
+ include ArgsHelper
122
+
148
123
  def self.included(klass)
149
124
  klass.class_eval do
150
125
  attr_accessor :queue_name
@@ -184,10 +159,10 @@ RSpec::Matchers.define :have_scheduled do |*expected_args|
184
159
  match do |actual|
185
160
  schedule_queue_for(actual).any? do |entry|
186
161
  class_matches = entry[:class].to_s == actual.to_s
187
- args_match = expected_args == entry[:args]
162
+ args_match = match_args(expected_args, entry[:args])
188
163
 
189
164
  time_matches = if @time
190
- entry[:time] == @time
165
+ entry[:time].to_i == @time.to_i
191
166
  elsif @interval
192
167
  entry[:time].to_i == (entry[:stored_at] + @interval).to_i
193
168
  else
@@ -198,11 +173,11 @@ RSpec::Matchers.define :have_scheduled do |*expected_args|
198
173
  end
199
174
  end
200
175
 
201
- failure_message_for_should do |actual|
176
+ failure_message do |actual|
202
177
  ["expected that #{actual} would have [#{expected_args.join(', ')}] scheduled", @time_info].join(' ')
203
178
  end
204
179
 
205
- failure_message_for_should_not do |actual|
180
+ failure_message_when_negated do |actual|
206
181
  ["expected that #{actual} would not have [#{expected_args.join(', ')}] scheduled", @time_info].join(' ')
207
182
  end
208
183
 
@@ -218,14 +193,14 @@ RSpec::Matchers.define :have_scheduled_at do |*expected_args|
218
193
  match do |actual|
219
194
  time = expected_args.first
220
195
  other_args = expected_args[1..-1]
221
- schedule_queue_for(actual).any? { |entry| entry[:class].to_s == actual.to_s && entry[:time] == time && other_args == entry[:args] }
196
+ schedule_queue_for(actual).any? { |entry| entry[:class].to_s == actual.to_s && entry[:time] == time && match_args(other_args, entry[:args]) }
222
197
  end
223
198
 
224
- failure_message_for_should do |actual|
199
+ failure_message do |actual|
225
200
  "expected that #{actual} would have [#{expected_args.join(', ')}] scheduled"
226
201
  end
227
202
 
228
- failure_message_for_should_not do |actual|
203
+ failure_message_when_negated do |actual|
229
204
  "expected that #{actual} would not have [#{expected_args.join(', ')}] scheduled"
230
205
  end
231
206
 
@@ -241,11 +216,11 @@ RSpec::Matchers.define :have_schedule_size_of do |size|
241
216
  schedule_queue_for(actual).size == size
242
217
  end
243
218
 
244
- failure_message_for_should do |actual|
219
+ failure_message do |actual|
245
220
  "expected that #{actual} would have #{size} scheduled entries, but got #{schedule_queue_for(actual).size} instead"
246
221
  end
247
222
 
248
- failure_message_for_should_not do |actual|
223
+ failure_message_when_negated do |actual|
249
224
  "expected that #{actual} would have #{size} scheduled entries."
250
225
  end
251
226
 
@@ -261,11 +236,11 @@ RSpec::Matchers.define :have_schedule_size_of_at_least do |size|
261
236
  schedule_queue_for(actual).size >= size
262
237
  end
263
238
 
264
- failure_message_for_should do |actual|
239
+ failure_message do |actual|
265
240
  "expected that #{actual} would have at least #{size} scheduled entries, but got #{schedule_queue_for(actual).size} instead"
266
241
  end
267
242
 
268
- failure_message_for_should_not do |actual|
243
+ failure_message_when_negated do |actual|
269
244
  "expected that #{actual} would have at least #{size} scheduled entries."
270
245
  end
271
246
 
@@ -1,4 +1,5 @@
1
1
  require 'resque_spec'
2
+ require 'resque-scheduler'
2
3
 
3
4
  module ResqueSpec
4
5
  module SchedulerExt
@@ -7,6 +8,8 @@ module ResqueSpec
7
8
  klass.instance_eval do
8
9
  alias :enqueue_at_without_resque_spec :enqueue_at
9
10
  alias :enqueue_in_without_resque_spec :enqueue_in
11
+ alias :enqueue_at_with_queue_without_resque_spec :enqueue_at_with_queue
12
+ alias :enqueue_in_with_queue_without_resque_spec :enqueue_in_with_queue
10
13
  alias :remove_delayed_without_resque_spec :remove_delayed
11
14
  end
12
15
  end
@@ -22,7 +25,7 @@ module ResqueSpec
22
25
  end
23
26
 
24
27
  def enqueue_at_with_queue(queue, time, klass, *args)
25
- return enqueue_at_with_queue_without_resque_spec(time, klass, *args) if ResqueSpec.disable_ext && respond_to?(:enqueue_at_with_queue_without_resque_spec)
28
+ return enqueue_at_with_queue_without_resque_spec(queue, time, klass, *args) if ResqueSpec.disable_ext
26
29
 
27
30
  ResqueSpec.enqueue_at_with_queue(queue, time, klass, *args)
28
31
  end
@@ -34,7 +37,7 @@ module ResqueSpec
34
37
  end
35
38
 
36
39
  def enqueue_in_with_queue(queue, time, klass, *args)
37
- return enqueue_in_with_queue_without_resque_spec(time, klass, *args) if ResqueSpec.disable_ext && respond_to?(:enqueue_in_with_queue_without_resque_spec)
40
+ return enqueue_in_with_queue_without_resque_spec(queue, time, klass, *args) if ResqueSpec.disable_ext
38
41
 
39
42
  ResqueSpec.enqueue_in_with_queue(queue, time, klass, *args)
40
43
  end
@@ -1,3 +1,3 @@
1
1
  module ResqueSpec
2
- VERSION = "0.15.0"
2
+ VERSION = "0.18.1"
3
3
  end
metadata CHANGED
@@ -1,216 +1,193 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: resque_spec
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.15.0
5
- prerelease:
4
+ version: 0.18.1
6
5
  platform: ruby
7
6
  authors:
8
7
  - Les Hill
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2014-02-02 00:00:00.000000000 Z
11
+ date: 2018-11-16 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: resque
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - ">="
20
18
  - !ruby/object:Gem::Version
21
- version: 1.19.0
19
+ version: 1.26.0
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ! '>='
24
+ - - ">="
28
25
  - !ruby/object:Gem::Version
29
- version: 1.19.0
26
+ version: 1.26.0
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: rspec-core
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ! '>='
31
+ - - ">="
36
32
  - !ruby/object:Gem::Version
37
- version: 2.5.0
33
+ version: 3.0.0
38
34
  type: :runtime
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ! '>='
38
+ - - ">="
44
39
  - !ruby/object:Gem::Version
45
- version: 2.5.0
40
+ version: 3.0.0
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: rspec-expectations
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
- - - ! '>='
45
+ - - ">="
52
46
  - !ruby/object:Gem::Version
53
- version: 2.5.0
47
+ version: 3.0.0
54
48
  type: :runtime
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
- - - ! '>='
52
+ - - ">="
60
53
  - !ruby/object:Gem::Version
61
- version: 2.5.0
54
+ version: 3.0.0
62
55
  - !ruby/object:Gem::Dependency
63
56
  name: rspec-mocks
64
57
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
58
  requirements:
67
- - - ! '>='
59
+ - - ">="
68
60
  - !ruby/object:Gem::Version
69
- version: 2.5.0
61
+ version: 3.0.0
70
62
  type: :runtime
71
63
  prerelease: false
72
64
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
65
  requirements:
75
- - - ! '>='
66
+ - - ">="
76
67
  - !ruby/object:Gem::Version
77
- version: 2.5.0
68
+ version: 3.0.0
78
69
  - !ruby/object:Gem::Dependency
79
70
  name: resque-scheduler
80
71
  requirement: !ruby/object:Gem::Requirement
81
- none: false
82
72
  requirements:
83
- - - ! '>='
73
+ - - ">="
84
74
  - !ruby/object:Gem::Version
85
- version: '0'
75
+ version: 4.3.1
86
76
  type: :development
87
77
  prerelease: false
88
78
  version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
79
  requirements:
91
- - - ! '>='
80
+ - - ">="
92
81
  - !ruby/object:Gem::Version
93
- version: '0'
82
+ version: 4.3.1
94
83
  - !ruby/object:Gem::Dependency
95
84
  name: pry
96
85
  requirement: !ruby/object:Gem::Requirement
97
- none: false
98
86
  requirements:
99
- - - ! '>='
87
+ - - ">="
100
88
  - !ruby/object:Gem::Version
101
89
  version: '0'
102
90
  type: :development
103
91
  prerelease: false
104
92
  version_requirements: !ruby/object:Gem::Requirement
105
- none: false
106
93
  requirements:
107
- - - ! '>='
94
+ - - ">="
108
95
  - !ruby/object:Gem::Version
109
96
  version: '0'
110
97
  - !ruby/object:Gem::Dependency
111
- name: pry-debugger
98
+ name: pry-byebug
112
99
  requirement: !ruby/object:Gem::Requirement
113
- none: false
114
100
  requirements:
115
- - - ! '>='
101
+ - - ">="
116
102
  - !ruby/object:Gem::Version
117
103
  version: '0'
118
104
  type: :development
119
105
  prerelease: false
120
106
  version_requirements: !ruby/object:Gem::Requirement
121
- none: false
122
107
  requirements:
123
- - - ! '>='
108
+ - - ">="
124
109
  - !ruby/object:Gem::Version
125
110
  version: '0'
126
111
  - !ruby/object:Gem::Dependency
127
112
  name: timecop
128
113
  requirement: !ruby/object:Gem::Requirement
129
- none: false
130
114
  requirements:
131
- - - ! '>='
115
+ - - ">="
132
116
  - !ruby/object:Gem::Version
133
117
  version: '0'
134
118
  type: :development
135
119
  prerelease: false
136
120
  version_requirements: !ruby/object:Gem::Requirement
137
- none: false
138
121
  requirements:
139
- - - ! '>='
122
+ - - ">="
140
123
  - !ruby/object:Gem::Version
141
124
  version: '0'
142
125
  - !ruby/object:Gem::Dependency
143
126
  name: rake
144
127
  requirement: !ruby/object:Gem::Requirement
145
- none: false
146
128
  requirements:
147
- - - ! '>='
129
+ - - ">="
148
130
  - !ruby/object:Gem::Version
149
131
  version: '0'
150
132
  type: :development
151
133
  prerelease: false
152
134
  version_requirements: !ruby/object:Gem::Requirement
153
- none: false
154
135
  requirements:
155
- - - ! '>='
136
+ - - ">="
156
137
  - !ruby/object:Gem::Version
157
138
  version: '0'
158
139
  - !ruby/object:Gem::Dependency
159
140
  name: rspec
160
141
  requirement: !ruby/object:Gem::Requirement
161
- none: false
162
142
  requirements:
163
- - - ! '>='
143
+ - - ">="
164
144
  - !ruby/object:Gem::Version
165
- version: 2.10.0
145
+ version: 3.0.0
166
146
  type: :development
167
147
  prerelease: false
168
148
  version_requirements: !ruby/object:Gem::Requirement
169
- none: false
170
149
  requirements:
171
- - - ! '>='
150
+ - - ">="
172
151
  - !ruby/object:Gem::Version
173
- version: 2.10.0
152
+ version: 3.0.0
174
153
  description: RSpec matchers for Resque
175
154
  email: leshill@gmail.com
176
155
  executables: []
177
156
  extensions: []
178
157
  extra_rdoc_files: []
179
158
  files:
159
+ - LICENSE
160
+ - README.md
161
+ - Rakefile
162
+ - lib/resque_spec.rb
180
163
  - lib/resque_spec/cucumber.rb
181
164
  - lib/resque_spec/ext.rb
182
165
  - lib/resque_spec/helpers.rb
183
166
  - lib/resque_spec/matchers.rb
184
167
  - lib/resque_spec/scheduler.rb
185
168
  - lib/resque_spec/version.rb
186
- - lib/resque_spec.rb
187
- - LICENSE
188
- - README.md
189
- - Rakefile
190
169
  homepage: http://github.com/leshill/resque_spec
191
170
  licenses:
192
171
  - MIT
172
+ metadata: {}
193
173
  post_install_message:
194
174
  rdoc_options: []
195
175
  require_paths:
196
176
  - lib
197
177
  required_ruby_version: !ruby/object:Gem::Requirement
198
- none: false
199
178
  requirements:
200
- - - ! '>='
179
+ - - ">="
201
180
  - !ruby/object:Gem::Version
202
181
  version: '0'
203
182
  required_rubygems_version: !ruby/object:Gem::Requirement
204
- none: false
205
183
  requirements:
206
- - - ! '>='
184
+ - - ">="
207
185
  - !ruby/object:Gem::Version
208
186
  version: 1.3.6
209
187
  requirements: []
210
188
  rubyforge_project:
211
- rubygems_version: 1.8.23
189
+ rubygems_version: 2.7.6
212
190
  signing_key:
213
- specification_version: 3
191
+ specification_version: 4
214
192
  summary: RSpec matchers for Resque
215
193
  test_files: []
216
- has_rdoc: