resque_spec 0.6.6 → 0.6.7
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +27 -2
- data/lib/resque_spec/scheduler.rb +1 -1
- data/lib/resque_spec/version.rb +1 -1
- data/lib/resque_spec.rb +19 -3
- metadata +2 -2
data/README.md
CHANGED
@@ -145,8 +145,13 @@ Performing Jobs in Specs
|
|
145
145
|
------------------------
|
146
146
|
|
147
147
|
Normally, Resque does not perform queued jobs within tests. You may want to
|
148
|
-
make assertions based on the result of your jobs.
|
149
|
-
|
148
|
+
make assertions based on the result of your jobs. ResqueSpec can process jobs
|
149
|
+
immediately as they are queued or under your control.
|
150
|
+
|
151
|
+
Performing jobs immediately
|
152
|
+
===========================
|
153
|
+
|
154
|
+
To perform jobs immediately, you can pass a block to the `with_resque` helper:
|
150
155
|
|
151
156
|
Given this scenario
|
152
157
|
|
@@ -180,6 +185,26 @@ Or I write this spec using the `with_resque` helper
|
|
180
185
|
|
181
186
|
You can turn this behavior on by setting `ResqueSpec.inline = true`.
|
182
187
|
|
188
|
+
Performing jobs at your discretion
|
189
|
+
===================================
|
190
|
+
|
191
|
+
You can perform the first job on a queue at a time, or perform all the jobs on
|
192
|
+
a queue. Use `ResqueSpec#perform_next(queue_name)` or
|
193
|
+
`ResqueSpec#perform_all(queue_name)`
|
194
|
+
|
195
|
+
Given this scenario:
|
196
|
+
|
197
|
+
Given a game
|
198
|
+
When I score
|
199
|
+
And the score queue runs
|
200
|
+
Then the game has a score
|
201
|
+
|
202
|
+
I might write this as a Cucumber step
|
203
|
+
|
204
|
+
When /the (\w+) queue runs/ do |queue_name|
|
205
|
+
ResqueSpec.perform_all(queue_name)
|
206
|
+
end
|
207
|
+
|
183
208
|
Hooks
|
184
209
|
-----
|
185
210
|
|
@@ -12,7 +12,7 @@ module ResqueSpec
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def enqueue_at(time, klass, *args)
|
15
|
-
store(schedule_queue_name(klass),
|
15
|
+
store(schedule_queue_name(klass), :class => klass.to_s, :time => time, :args => args)
|
16
16
|
end
|
17
17
|
|
18
18
|
def enqueue_in(time, klass, *args)
|
data/lib/resque_spec/version.rb
CHANGED
data/lib/resque_spec.rb
CHANGED
@@ -14,7 +14,18 @@ module ResqueSpec
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def enqueue(queue_name, klass, *args)
|
17
|
-
store(queue_name,
|
17
|
+
store(queue_name, :class => klass.to_s, :args => args)
|
18
|
+
end
|
19
|
+
|
20
|
+
def perform_next(queue_name)
|
21
|
+
perform(queue_name, queue_by_name(queue_name).shift)
|
22
|
+
end
|
23
|
+
|
24
|
+
def perform_all(queue_name)
|
25
|
+
queue = queue_by_name(queue_name)
|
26
|
+
until queue.empty?
|
27
|
+
perform(queue_name, queue.shift)
|
28
|
+
end
|
18
29
|
end
|
19
30
|
|
20
31
|
def queue_by_name(name)
|
@@ -41,6 +52,7 @@ module ResqueSpec
|
|
41
52
|
|
42
53
|
def reset!
|
43
54
|
queues.clear
|
55
|
+
self.inline = false
|
44
56
|
end
|
45
57
|
|
46
58
|
private
|
@@ -53,9 +65,13 @@ module ResqueSpec
|
|
53
65
|
klass.respond_to?(:queue) and klass.queue
|
54
66
|
end
|
55
67
|
|
56
|
-
def
|
68
|
+
def perform(queue_name, payload)
|
69
|
+
Resque::Job.new(queue_name, payload_with_string_keys(payload)).perform
|
70
|
+
end
|
71
|
+
|
72
|
+
def store(queue_name, payload)
|
57
73
|
if inline
|
58
|
-
|
74
|
+
perform(queue_name, payload)
|
59
75
|
else
|
60
76
|
queue_by_name(queue_name) << payload
|
61
77
|
end
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: resque_spec
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.6.
|
5
|
+
version: 0.6.7
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Les Hill
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-
|
13
|
+
date: 2011-07-14 00:00:00 -07:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|