resque_spec 0.12.6 → 0.12.7

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/README.md CHANGED
@@ -208,6 +208,21 @@ You can also check the size of the schedule:
208
208
 
209
209
  (And I take note of the `before` block that is calling `reset!` for every spec)
210
210
 
211
+ You can explicitly specify the queue when using enqueue_at_with_queue and
212
+ enqueue_in_with_queue:
213
+
214
+ describe "#recalculate_in_future" do
215
+ before do
216
+ ResqueSpec.reset!
217
+ end
218
+
219
+ it "adds person.calculate to the :future queue" do
220
+ person.recalculate_in_future
221
+
222
+ Person.should have_schedule_size_of(1).queue(:future)
223
+ end
224
+ end
225
+
211
226
  And I might write this as a Cucumber step
212
227
 
213
228
  Then /the (\w?) has (\w?) scheduled/ do |thing, method|
@@ -223,6 +238,10 @@ Then I write some code to make it pass:
223
238
  def recalculate
224
239
  Resque.enqueue_at(Time.now + 3600, Person, id, :calculate)
225
240
  end
241
+
242
+ def recalculate_in_future
243
+ Resque.enqueue_at_with_queue(:future, Time.now + 3600, Person, id, :calculate)
244
+ end
226
245
  end
227
246
 
228
247
  Performing Jobs in Specs
@@ -350,6 +369,7 @@ Contributors
350
369
  * @opinel (Frank Wambutt) :Fix DST problem in `have\_scheduled`
351
370
  * @lukemelia (Luke Melia) :Add `times` chained matcher
352
371
  * @heelhook (Pablo Fernandez) :Add `have_queue_size_of_at_least` and `have_schedule_size_of_at_least` matchers
372
+ * @k1w1 :Add support for enqueue_at_with_queue/enqueue_in_with_queue
353
373
 
354
374
  Copyright
355
375
  =========
@@ -104,7 +104,33 @@ RSpec::Matchers.define :have_queue_size_of_at_least do |size|
104
104
  end
105
105
  end
106
106
 
107
+ module ScheduleQueueHelper
108
+ def self.extended(klass)
109
+ klass.instance_eval do
110
+ self.queue_name = nil
111
+ chain :queue do |queue_name|
112
+ self.queue_name = queue_name
113
+ end
114
+ end
115
+ end
116
+
117
+ private
118
+
119
+ attr_accessor :queue_name
120
+
121
+ def schedule_queue_for(actual)
122
+ if @queue_name
123
+ ResqueSpec.queue_by_name(@queue_name)
124
+ else
125
+ ResqueSpec.schedule_for(actual)
126
+ end
127
+ end
128
+
129
+ end
130
+
107
131
  RSpec::Matchers.define :have_scheduled do |*expected_args|
132
+ extend ScheduleQueueHelper
133
+
108
134
  chain :at do |timestamp|
109
135
  @interval = nil
110
136
  @time = timestamp
@@ -118,7 +144,7 @@ RSpec::Matchers.define :have_scheduled do |*expected_args|
118
144
  end
119
145
 
120
146
  match do |actual|
121
- ResqueSpec.schedule_for(actual).any? do |entry|
147
+ schedule_queue_for(actual).any? do |entry|
122
148
  class_matches = entry[:class].to_s == actual.to_s
123
149
  args_match = expected_args == entry[:args]
124
150
 
@@ -148,12 +174,13 @@ RSpec::Matchers.define :have_scheduled do |*expected_args|
148
174
  end
149
175
 
150
176
  RSpec::Matchers.define :have_scheduled_at do |*expected_args|
177
+ extend ScheduleQueueHelper
151
178
  warn "DEPRECATION WARNING: have_scheduled_at(time, *args) is deprecated and will be removed in future. Please use have_scheduled(*args).at(time) instead."
152
179
 
153
180
  match do |actual|
154
181
  time = expected_args.first
155
182
  other_args = expected_args[1..-1]
156
- ResqueSpec.schedule_for(actual).any? { |entry| entry[:class].to_s == actual.to_s && entry[:time] == time && other_args == entry[:args] }
183
+ schedule_queue_for(actual).any? { |entry| entry[:class].to_s == actual.to_s && entry[:time] == time && other_args == entry[:args] }
157
184
  end
158
185
 
159
186
  failure_message_for_should do |actual|
@@ -170,12 +197,14 @@ RSpec::Matchers.define :have_scheduled_at do |*expected_args|
170
197
  end
171
198
 
172
199
  RSpec::Matchers.define :have_schedule_size_of do |size|
200
+ extend ScheduleQueueHelper
201
+
173
202
  match do |actual|
174
- ResqueSpec.schedule_for(actual).size == size
203
+ schedule_queue_for(actual).size == size
175
204
  end
176
205
 
177
206
  failure_message_for_should do |actual|
178
- "expected that #{actual} would have #{size} scheduled entries, but got #{ResqueSpec.schedule_for(actual).size} instead"
207
+ "expected that #{actual} would have #{size} scheduled entries, but got #{schedule_queue_for(actual).size} instead"
179
208
  end
180
209
 
181
210
  failure_message_for_should_not do |actual|
@@ -188,12 +217,14 @@ RSpec::Matchers.define :have_schedule_size_of do |size|
188
217
  end
189
218
 
190
219
  RSpec::Matchers.define :have_schedule_size_of_at_least do |size|
220
+ extend ScheduleQueueHelper
221
+
191
222
  match do |actual|
192
- ResqueSpec.schedule_for(actual).size >= size
223
+ schedule_queue_for(actual).size >= size
193
224
  end
194
225
 
195
226
  failure_message_for_should do |actual|
196
- "expected that #{actual} would have at least #{size} scheduled entries, but got #{ResqueSpec.schedule_for(actual).size} instead"
227
+ "expected that #{actual} would have at least #{size} scheduled entries, but got #{schedule_queue_for(actual).size} instead"
197
228
  end
198
229
 
199
230
  failure_message_for_should_not do |actual|
@@ -203,4 +234,4 @@ RSpec::Matchers.define :have_schedule_size_of_at_least do |size|
203
234
  description do
204
235
  "have schedule size of #{size}"
205
236
  end
206
- end
237
+ end
@@ -21,12 +21,24 @@ module ResqueSpec
21
21
  ResqueSpec.enqueue_at(time, klass, *args)
22
22
  end
23
23
 
24
+ 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)
26
+
27
+ ResqueSpec.enqueue_at_with_queue(queue, time, klass, *args)
28
+ end
29
+
24
30
  def enqueue_in(time, klass, *args)
25
31
  return enqueue_in_without_resque_spec(time, klass, *args) if ResqueSpec.disable_ext && respond_to?(:enqueue_in_without_resque_spec)
26
32
 
27
33
  ResqueSpec.enqueue_in(time, klass, *args)
28
34
  end
29
35
 
36
+ 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)
38
+
39
+ ResqueSpec.enqueue_in_with_queue(queue, time, klass, *args)
40
+ end
41
+
30
42
  def remove_delayed(klass, *args)
31
43
  return remove_delayed_without_resque_spec(klass, *args) if ResqueSpec.disable_ext && respond_to?(:remove_delayed_without_resque_spec)
32
44
 
@@ -35,14 +47,22 @@ module ResqueSpec
35
47
  end
36
48
 
37
49
  def enqueue_at(time, klass, *args)
50
+ enqueue_at_with_queue(schedule_queue_name(klass), time, klass, *args)
51
+ end
52
+
53
+ def enqueue_at_with_queue(queue, time, klass, *args)
38
54
  is_time?(time)
39
- perform_or_store(schedule_queue_name(klass), :class => klass.to_s, :time => time, :stored_at => Time.now, :args => args)
55
+ perform_or_store(queue, :class => klass.to_s, :time => time, :stored_at => Time.now, :args => args)
40
56
  end
41
57
 
42
58
  def enqueue_in(time, klass, *args)
43
59
  enqueue_at(Time.now + time, klass, *args)
44
60
  end
45
61
 
62
+ def enqueue_in_with_queue(queue, time, klass, *args)
63
+ enqueue_at_with_queue(queue, Time.now + time, klass, *args)
64
+ end
65
+
46
66
  def remove_delayed(klass, *args)
47
67
  sched_queue = queue_by_name(schedule_queue_name(klass))
48
68
  count_before_remove = sched_queue.length
@@ -1,3 +1,3 @@
1
1
  module ResqueSpec
2
- VERSION = "0.12.6"
2
+ VERSION = "0.12.7"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: resque_spec
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.12.6
4
+ version: 0.12.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-11-21 00:00:00.000000000 Z
12
+ date: 2012-12-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: resque