resque_unit 0.2.2 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/resque_unit/assertions.rb +2 -2
- data/lib/resque_unit/resque.rb +4 -1
- data/test/resque_unit_test.rb +74 -0
- data/test/sample_jobs.rb +8 -1
- data/test/test_helper.rb +1 -0
- metadata +4 -4
@@ -9,7 +9,7 @@ module ResqueUnit::Assertions
|
|
9
9
|
# want to assert that klass has been queued without arguments.
|
10
10
|
def assert_queued(klass, args = nil, message = nil)
|
11
11
|
queue = Resque.queue_for(klass)
|
12
|
-
assert_block (message || "#{klass} should have been queued in #{queue}: #{Resque.queue(queue).inspect}.") do
|
12
|
+
assert_block (message || "#{klass}#{args ? " with #{args.inspect}" : ""} should have been queued in #{queue}: #{Resque.queue(queue).inspect}.") do
|
13
13
|
in_queue?(queue, klass, args)
|
14
14
|
end
|
15
15
|
end
|
@@ -17,7 +17,7 @@ module ResqueUnit::Assertions
|
|
17
17
|
# The opposite of +assert_queued+.
|
18
18
|
def assert_not_queued(klass, args = nil, message = nil)
|
19
19
|
queue = Resque.queue_for(klass)
|
20
|
-
assert_block (message || "#{klass} should not have been queued in #{queue}.") do
|
20
|
+
assert_block (message || "#{klass}#{args ? " with #{args.inspect}" : ""} should not have been queued in #{queue}.") do
|
21
21
|
!in_queue?(queue, klass, args)
|
22
22
|
end
|
23
23
|
end
|
data/lib/resque_unit/resque.rb
CHANGED
data/test/resque_unit_test.rb
CHANGED
@@ -101,7 +101,81 @@ class ResqueUnitTest < Test::Unit::TestCase
|
|
101
101
|
assert_not_queued(JobWithArguments, [1, "test"])
|
102
102
|
end
|
103
103
|
end
|
104
|
+
end
|
105
|
+
|
106
|
+
context "A job that schedules a new resque job" do
|
107
|
+
setup do
|
108
|
+
Resque.enqueue(JobThatCreatesANewJob)
|
109
|
+
end
|
110
|
+
|
111
|
+
should "pass the assert_queued(job) assertion" do
|
112
|
+
assert_queued(JobThatCreatesANewJob)
|
113
|
+
end
|
104
114
|
|
115
|
+
should "fail the assert_not_queued(job) assertion" do
|
116
|
+
assert_raise Test::Unit::AssertionFailedError do
|
117
|
+
assert_not_queued(JobThatCreatesANewJob)
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
should "pass the assert_not_queued(LowPriorityJob) assertion" do
|
122
|
+
assert_not_queued(LowPriorityJob)
|
123
|
+
end
|
124
|
+
|
125
|
+
context ", when Resque.run! is called," do
|
126
|
+
setup do
|
127
|
+
Resque.run!
|
128
|
+
end
|
129
|
+
|
130
|
+
should "clear the job from the queue" do
|
131
|
+
assert_not_queued(JobThatCreatesANewJob)
|
132
|
+
end
|
133
|
+
|
134
|
+
should "add a LowPriorityJob" do
|
135
|
+
assert_queued(LowPriorityJob)
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
context "An assertion message" do
|
141
|
+
context "of assert_queued" do
|
142
|
+
should "include job class and queue content" do
|
143
|
+
begin
|
144
|
+
assert_not_queued(LowPriorityJob)
|
145
|
+
rescue Test::Unit::AssertionFailedError => error
|
146
|
+
assert_equal "LowPriorityJob should have been queued in low: [].", error.message
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
should "include job arguments if provided" do
|
151
|
+
begin
|
152
|
+
assert_not_queued(JobWithArguments, [1, "test"])
|
153
|
+
rescue Test::Unit::AssertionFailedError => error
|
154
|
+
assert_equal "JobWithArguments with [1, \"test\"] should have been queued in medium: [].", error.message
|
155
|
+
end
|
156
|
+
end
|
157
|
+
end
|
105
158
|
end
|
106
159
|
|
160
|
+
context "An assertion message" do
|
161
|
+
context "of assert_not_queued" do
|
162
|
+
should "include job class and queue content" do
|
163
|
+
begin
|
164
|
+
Resque.enqueue(LowPriorityJob)
|
165
|
+
assert_not_queued(LowPriorityJob)
|
166
|
+
rescue Test::Unit::AssertionFailedError => error
|
167
|
+
assert_equal "LowPriorityJob should not have been queued in low.", error.message
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
should "include job arguments if provided" do
|
172
|
+
begin
|
173
|
+
Resque.enqueue(JobWithArguments, 1, "test")
|
174
|
+
assert_not_queued(JobWithArguments, [1, "test"])
|
175
|
+
rescue Test::Unit::AssertionFailedError => error
|
176
|
+
assert_equal "JobWithArguments with [1, \"test\"] should not have been queued in medium.", error.message
|
177
|
+
end
|
178
|
+
end
|
179
|
+
end
|
180
|
+
end
|
107
181
|
end
|
data/test/sample_jobs.rb
CHANGED
@@ -12,7 +12,6 @@ class LowPriorityJob
|
|
12
12
|
def self.run=(value)
|
13
13
|
@run = value
|
14
14
|
end
|
15
|
-
|
16
15
|
end
|
17
16
|
|
18
17
|
class MediumPriorityJob
|
@@ -28,3 +27,11 @@ class JobWithArguments
|
|
28
27
|
|
29
28
|
end
|
30
29
|
end
|
30
|
+
|
31
|
+
class JobThatCreatesANewJob
|
32
|
+
@queue = :spawn
|
33
|
+
|
34
|
+
def self.perform
|
35
|
+
Resque.enqueue(LowPriorityJob)
|
36
|
+
end
|
37
|
+
end
|
data/test/test_helper.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: resque_unit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 17
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 2
|
9
|
-
-
|
10
|
-
version: 0.2.
|
9
|
+
- 3
|
10
|
+
version: 0.2.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Justin Weiss
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-07-
|
18
|
+
date: 2010-07-26 00:00:00 -07:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|