resque_spec 0.6.2 → 0.6.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +2 -7
- data/lib/resque_spec/matchers.rb +3 -3
- data/lib/resque_spec/scheduler.rb +15 -10
- data/lib/resque_spec/version.rb +1 -1
- data/lib/resque_spec.rb +17 -6
- metadata +2 -2
data/README.md
CHANGED
@@ -181,13 +181,8 @@ You can turn this behavior on by setting `ResqueSpec.inline = true`.
|
|
181
181
|
Hooks
|
182
182
|
-----
|
183
183
|
|
184
|
-
Resque will call a hook method on your class after a Job is enqueued
|
185
|
-
|
186
|
-
you want) and it will be called with the arguments to the Job after it has been
|
187
|
-
placed on the queue. When you are using ResqueSpec, your `after_enqueue` hook
|
188
|
-
will be called.
|
189
|
-
|
190
|
-
The hooks around `perform` are not support by ResqueSpec (contributions welcome!)
|
184
|
+
Resque will call a hook method on your class after a Job is enqueued; before, around, and after your Job is performed; and on failure.
|
185
|
+
ResqueSpec will fire all of these hooks if you are using `with_resque` or set `ResqueSpec.inline = true`.
|
191
186
|
|
192
187
|
Note on Patches/Pull Requests
|
193
188
|
=============================
|
data/lib/resque_spec/matchers.rb
CHANGED
@@ -27,7 +27,7 @@ RSpec::Matchers.define :have_queued do |*expected_args|
|
|
27
27
|
extend InQueueHelper
|
28
28
|
|
29
29
|
match do |actual|
|
30
|
-
queue(actual).any? { |entry| entry[:
|
30
|
+
queue(actual).any? { |entry| entry[:class].to_s == actual.to_s && entry[:args] == expected_args }
|
31
31
|
end
|
32
32
|
|
33
33
|
failure_message_for_should do |actual|
|
@@ -65,7 +65,7 @@ end
|
|
65
65
|
|
66
66
|
RSpec::Matchers.define :have_scheduled do |*expected_args|
|
67
67
|
match do |actual|
|
68
|
-
ResqueSpec.schedule_for(actual).any? { |entry| entry[:
|
68
|
+
ResqueSpec.schedule_for(actual).any? { |entry| entry[:class].to_s == actual.to_s && entry[:args] == expected_args }
|
69
69
|
end
|
70
70
|
|
71
71
|
failure_message_for_should do |actual|
|
@@ -85,7 +85,7 @@ RSpec::Matchers.define :have_scheduled_at do |*expected_args|
|
|
85
85
|
match do |actual|
|
86
86
|
time = expected_args.first
|
87
87
|
other_args = expected_args[1..-1]
|
88
|
-
ResqueSpec.schedule_for(actual).any? { |entry| entry[:
|
88
|
+
ResqueSpec.schedule_for(actual).any? { |entry| entry[:class].to_s == actual.to_s && entry[:time] == time && entry[:args] == other_args }
|
89
89
|
end
|
90
90
|
|
91
91
|
failure_message_for_should do |actual|
|
@@ -1,20 +1,25 @@
|
|
1
1
|
require 'resque_spec'
|
2
2
|
|
3
3
|
module ResqueSpec
|
4
|
-
def schedule_for(klass)
|
5
|
-
name = "#{queue_name(klass)}_scheduled"
|
6
|
-
queues[name]
|
7
|
-
end
|
8
|
-
|
9
4
|
module SchedulerExt
|
10
5
|
def enqueue_at(time, klass, *args)
|
11
|
-
|
12
|
-
klass.send(:perform, *args)
|
13
|
-
else
|
14
|
-
ResqueSpec.schedule_for(klass) << {:klass => klass.to_s, :time => time, :args => args}
|
15
|
-
end
|
6
|
+
ResqueSpec.enqueue_at(time, klass, *args)
|
16
7
|
end
|
17
8
|
end
|
9
|
+
|
10
|
+
def enqueue_at(time, klass, *args)
|
11
|
+
store(schedule_queue_name(klass), klass, { :class => klass.to_s, :time => time, :args => args })
|
12
|
+
end
|
13
|
+
|
14
|
+
def schedule_for(klass)
|
15
|
+
queues[schedule_queue_name(klass)]
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def schedule_queue_name(klass)
|
21
|
+
"#{queue_name(klass)}_scheduled"
|
22
|
+
end
|
18
23
|
end
|
19
24
|
|
20
25
|
Resque.extend(ResqueSpec::SchedulerExt)
|
data/lib/resque_spec/version.rb
CHANGED
data/lib/resque_spec.rb
CHANGED
@@ -9,16 +9,12 @@ module ResqueSpec
|
|
9
9
|
|
10
10
|
def dequeue(queue_name, klass, *args)
|
11
11
|
queue_by_name(queue_name).delete_if do |job|
|
12
|
-
job[:
|
12
|
+
job[:class] == klass.to_s && args.empty? || job[:args] == args
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
16
16
|
def enqueue(queue_name, klass, *args)
|
17
|
-
|
18
|
-
klass.send(:perform, *args)
|
19
|
-
else
|
20
|
-
queue_by_name(queue_name) << { :klass => klass.to_s, :args => args }
|
21
|
-
end
|
17
|
+
store(queue_name, klass, { :class => klass.to_s, :args => args })
|
22
18
|
end
|
23
19
|
|
24
20
|
def queue_by_name(name)
|
@@ -56,6 +52,21 @@ module ResqueSpec
|
|
56
52
|
def name_from_queue_accessor(klass)
|
57
53
|
klass.respond_to?(:queue) and klass.queue
|
58
54
|
end
|
55
|
+
|
56
|
+
def store(queue_name, klass, payload)
|
57
|
+
if inline
|
58
|
+
Resque::Job.new(queue_name, payload_with_string_keys(payload)).perform
|
59
|
+
else
|
60
|
+
queue_by_name(queue_name) << payload
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def payload_with_string_keys(payload)
|
65
|
+
{
|
66
|
+
'class' => payload[:class],
|
67
|
+
'args' => payload[:args]
|
68
|
+
}
|
69
|
+
end
|
59
70
|
end
|
60
71
|
|
61
72
|
config = RSpec.configuration
|
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.3
|
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-04-
|
13
|
+
date: 2011-04-15 00:00:00 -04:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|