resque_spec 0.7.0 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +60 -26
- data/lib/resque_spec/ext.rb +19 -2
- data/lib/resque_spec/version.rb +1 -1
- data/lib/resque_spec.rb +10 -1
- metadata +12 -12
data/README.md
CHANGED
@@ -1,16 +1,13 @@
|
|
1
1
|
ResqueSpec
|
2
2
|
==========
|
3
3
|
|
4
|
-
A
|
5
|
-
|
4
|
+
A test double of Resque for RSpec and Cucumber. The code was originally based
|
5
|
+
on
|
6
6
|
[http://github.com/justinweiss/resque_unit](http://github.com/justinweiss/resque_unit).
|
7
7
|
|
8
8
|
ResqueSpec will also fire Resque hooks if you are using them. See below.
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
If you are using `RSpec ~> 1.3.0`, you should use version `~> 0.2.0`. This
|
13
|
-
branch is not actively maintained.
|
10
|
+
The current version works with `Resque v1.19.0` and up and `RSpec v2.5.0` and up.
|
14
11
|
|
15
12
|
Install
|
16
13
|
-------
|
@@ -23,6 +20,15 @@ Update your Gemfile to include `resque_spec` only in the *test* group (Not using
|
|
23
20
|
gem 'resque_spec'
|
24
21
|
end
|
25
22
|
|
23
|
+
What is ResqueSpec?
|
24
|
+
===================
|
25
|
+
|
26
|
+
ResqueSpec is a fake of the *stable API* for Resque 1.19.x (which is `enqueue`,
|
27
|
+
`enqueue_to`, `dequeue`, `reserve`, and the Resque hooks). It does not have a
|
28
|
+
test double for Redis, so this may lead to some interesting and puzzling
|
29
|
+
behaviour if you use some of the popular Resque plugins (such as
|
30
|
+
`resque_lock`).
|
31
|
+
|
26
32
|
Resque with Specs
|
27
33
|
=================
|
28
34
|
|
@@ -77,6 +83,29 @@ Then I write some code to make it pass:
|
|
77
83
|
end
|
78
84
|
end
|
79
85
|
|
86
|
+
You can check the size of the queue in your specs too.
|
87
|
+
|
88
|
+
describe "#recalculate" do
|
89
|
+
before do
|
90
|
+
ResqueSpec.reset!
|
91
|
+
end
|
92
|
+
|
93
|
+
it "adds an entry to the Person queue" do
|
94
|
+
person.recalculate
|
95
|
+
Person.should have_queue_size_of(1)
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
ResqueMailer with Specs
|
100
|
+
=======================
|
101
|
+
|
102
|
+
To use with [ResqueMailer](https://github.com/zapnap/resque_mailer) you should
|
103
|
+
have an initializer that does *not* exclude the `test` (or `cucumber`)
|
104
|
+
environment. Your initializer will probably end up looking like:
|
105
|
+
|
106
|
+
# config/initializers/resque_mailer.rb
|
107
|
+
Resque::Mailer.excluded_environments = []
|
108
|
+
|
80
109
|
ResqueScheduler with Specs
|
81
110
|
==========================
|
82
111
|
|
@@ -122,26 +151,10 @@ Then I write some code to make it pass:
|
|
122
151
|
end
|
123
152
|
end
|
124
153
|
|
125
|
-
Queue Size Specs
|
126
|
-
================
|
127
|
-
|
128
|
-
You can check the size of the queue in your specs too.
|
129
|
-
|
130
|
-
describe "#recalculate" do
|
131
|
-
before do
|
132
|
-
ResqueSpec.reset!
|
133
|
-
end
|
134
|
-
|
135
|
-
it "adds an entry to the Person queue" do
|
136
|
-
person.recalculate
|
137
|
-
Person.should have_queue_size_of(1)
|
138
|
-
end
|
139
|
-
end
|
140
|
-
|
141
154
|
Performing Jobs in Specs
|
142
155
|
========================
|
143
156
|
|
144
|
-
Normally,
|
157
|
+
Normally, ResqueSpec does not perform queued jobs within tests. You may want to
|
145
158
|
make assertions based on the result of your jobs. ResqueSpec can process jobs
|
146
159
|
immediately as they are queued or under your control.
|
147
160
|
|
@@ -205,14 +218,19 @@ I might write this as a Cucumber step
|
|
205
218
|
Hooks
|
206
219
|
=====
|
207
220
|
|
208
|
-
Resque provides hooks at different points of the queueing lifecylce.
|
221
|
+
Resque provides hooks at different points of the queueing lifecylce.
|
222
|
+
ResqueSpec fires these hooks when appropriate.
|
209
223
|
|
210
|
-
The after enqueue
|
224
|
+
The before and after `enqueue` hooks are always called when you use
|
225
|
+
`Resque#enqueue`. If your `before_enqueue` hook returns `false`, the job will
|
226
|
+
not be queued and `after_enqueue` will not be called.
|
211
227
|
|
212
228
|
The `perform` hooks: before, around, after, and on failure are fired by
|
213
229
|
ResqueSpec if you are using the `with_resque` helper or set `ResqueSpec.inline = true`.
|
214
230
|
|
215
|
-
Important!
|
231
|
+
Important! If you are using ResqueScheduler, `Resque#enqueue_at/enqueue_in`
|
232
|
+
does not fire the after enqueue hook (the job has not been queued yet!), but
|
233
|
+
will fire the `perform` hooks if you are using `inline` mode.
|
216
234
|
|
217
235
|
Note on Patches/Pull Requests
|
218
236
|
=============================
|
@@ -225,6 +243,22 @@ Note on Patches/Pull Requests
|
|
225
243
|
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
226
244
|
* Send me a pull request. Bonus points for topic branches.
|
227
245
|
|
246
|
+
Contributors
|
247
|
+
============
|
248
|
+
|
249
|
+
* Les Hill (@leshill) : author
|
250
|
+
* Kenneth Kalmer (@kennethkalmer) : rspec dependency fix
|
251
|
+
* Brian Cardarella (@bcardarella) : fix mutation bug
|
252
|
+
* Joshua Davey (@joshdavey) : with_resque helper
|
253
|
+
* Lar Van Der Jagt (@supaspoida) : with_resque helper
|
254
|
+
* Evan Sagge (@evansagge) : Hook in via Job.create, have_queued.in
|
255
|
+
* Jon Larkowski (@l4rk) : inline perform
|
256
|
+
* James Conroy-Finn (@jcf) : spec fix
|
257
|
+
* Dennis Walters (@ess) : enqueue_in support
|
258
|
+
* (@RipTheJacker) : remove_delayed support
|
259
|
+
* Kurt Werle (@kwerle) : explicit require spec for v020
|
260
|
+
* (@dwilkie) : initial before_enqueue support
|
261
|
+
|
228
262
|
Copyright
|
229
263
|
=========
|
230
264
|
|
data/lib/resque_spec/ext.rb
CHANGED
@@ -21,15 +21,25 @@ module Resque
|
|
21
21
|
end
|
22
22
|
|
23
23
|
def enqueue(klass, *args)
|
24
|
+
enqueue_to(queue_from_class(klass), klass, *args)
|
25
|
+
end
|
26
|
+
|
27
|
+
def enqueue_to(queue, klass, *args)
|
24
28
|
if ResqueSpec.inline
|
29
|
+
return if run_before_enqueue(klass, *args)
|
25
30
|
run_after_enqueue(klass, *args)
|
26
|
-
Job.create(
|
31
|
+
Job.create(queue, klass, *args)
|
27
32
|
else
|
28
|
-
|
33
|
+
return if run_before_enqueue(klass, *args)
|
34
|
+
Job.create(queue, klass, *args)
|
29
35
|
run_after_enqueue(klass, *args)
|
30
36
|
end
|
31
37
|
end
|
32
38
|
|
39
|
+
def reserve(queue_name)
|
40
|
+
ResqueSpec.pop(queue_name)
|
41
|
+
end
|
42
|
+
|
33
43
|
private
|
34
44
|
|
35
45
|
def run_after_enqueue(klass, *args)
|
@@ -37,4 +47,11 @@ module Resque
|
|
37
47
|
klass.send(hook, *args)
|
38
48
|
end
|
39
49
|
end
|
50
|
+
|
51
|
+
def run_before_enqueue(klass, *args)
|
52
|
+
before_hooks = Plugin.before_enqueue_hooks(klass).collect do |hook|
|
53
|
+
klass.send(hook, *args)
|
54
|
+
end
|
55
|
+
before_hooks.any? { |result| result == false }
|
56
|
+
end
|
40
57
|
end
|
data/lib/resque_spec/version.rb
CHANGED
data/lib/resque_spec.rb
CHANGED
@@ -28,6 +28,11 @@ module ResqueSpec
|
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
31
|
+
def pop(queue_name)
|
32
|
+
return unless payload = queue_by_name(queue_name).shift
|
33
|
+
new_job(queue_name, payload)
|
34
|
+
end
|
35
|
+
|
31
36
|
def queue_by_name(name)
|
32
37
|
queues[name.to_s]
|
33
38
|
end
|
@@ -65,8 +70,12 @@ module ResqueSpec
|
|
65
70
|
klass.respond_to?(:queue) and klass.queue
|
66
71
|
end
|
67
72
|
|
73
|
+
def new_job(queue_name, payload)
|
74
|
+
Resque::Job.new(queue_name, payload_with_string_keys(payload))
|
75
|
+
end
|
76
|
+
|
68
77
|
def perform(queue_name, payload)
|
69
|
-
|
78
|
+
new_job(queue_name, payload).perform
|
70
79
|
end
|
71
80
|
|
72
81
|
def perform_or_store(queue_name, payload)
|
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.
|
4
|
+
version: 0.8.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,22 +9,22 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-
|
12
|
+
date: 2011-11-20 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: resque
|
16
|
-
requirement: &
|
16
|
+
requirement: &70321864755860 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version: 1.
|
21
|
+
version: 1.19.0
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70321864755860
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rspec
|
27
|
-
requirement: &
|
27
|
+
requirement: &70321864754320 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: 2.5.0
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70321864754320
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: ruby-debug19
|
38
|
-
requirement: &
|
38
|
+
requirement: &70321864753860 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70321864753860
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: timecop
|
49
|
-
requirement: &
|
49
|
+
requirement: &70321864753220 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,7 +54,7 @@ dependencies:
|
|
54
54
|
version: '0'
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70321864753220
|
58
58
|
description: RSpec matchers for Resque
|
59
59
|
email: leshill@gmail.com
|
60
60
|
executables: []
|
@@ -90,7 +90,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
90
90
|
version: 1.3.6
|
91
91
|
requirements: []
|
92
92
|
rubyforge_project:
|
93
|
-
rubygems_version: 1.8.
|
93
|
+
rubygems_version: 1.8.10
|
94
94
|
signing_key:
|
95
95
|
specification_version: 3
|
96
96
|
summary: RSpec matchers for Resque
|