resque_unit 0.3.5 → 0.3.6
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/resque_unit/assertions.rb +15 -11
- data/lib/resque_unit/helpers.rb +28 -1
- data/lib/resque_unit/resque.rb +7 -0
- data/test/resque_unit_test.rb +17 -0
- metadata +5 -5
@@ -10,17 +10,7 @@ module ResqueUnit::Assertions
|
|
10
10
|
# if you want to assert something was queued within its execution.
|
11
11
|
def assert_queued(klass, args = nil, message = nil, &block)
|
12
12
|
queue_name = Resque.queue_for(klass)
|
13
|
-
|
14
|
-
queue = if block_given?
|
15
|
-
snapshot = Resque.size(queue_name)
|
16
|
-
yield
|
17
|
-
Resque.queue(queue_name)[snapshot..-1]
|
18
|
-
else
|
19
|
-
Resque.queue(queue_name)
|
20
|
-
end
|
21
|
-
|
22
|
-
assert_with_custom_message(in_queue?(queue, klass, args),
|
23
|
-
message || "#{klass}#{args ? " with #{args.inspect}" : ""} should have been queued in #{queue_name}: #{queue.inspect}.")
|
13
|
+
assert_job_created(queue_name, klass, args, message, &block)
|
24
14
|
end
|
25
15
|
alias assert_queues assert_queued
|
26
16
|
|
@@ -48,6 +38,20 @@ module ResqueUnit::Assertions
|
|
48
38
|
assert_equal snapshot, present, message || "No jobs should have been queued"
|
49
39
|
end
|
50
40
|
|
41
|
+
# Asserts that a job was created and queued into the specified queue
|
42
|
+
def assert_job_created(queue_name, klass, args = nil, message = nil, &block)
|
43
|
+
queue = if block_given?
|
44
|
+
snapshot = Resque.size(queue_name)
|
45
|
+
yield
|
46
|
+
Resque.queue(queue_name)[snapshot..-1]
|
47
|
+
else
|
48
|
+
Resque.queue(queue_name)
|
49
|
+
end
|
50
|
+
|
51
|
+
assert_with_custom_message(in_queue?(queue, klass, args),
|
52
|
+
message || "#{klass}#{args ? " with #{args.inspect}" : ""} should have been queued in #{queue_name}: #{queue.inspect}.")
|
53
|
+
end
|
54
|
+
|
51
55
|
private
|
52
56
|
|
53
57
|
# In Test::Unit, +assert_block+ displays only the message on a test
|
data/lib/resque_unit/helpers.rb
CHANGED
@@ -26,5 +26,32 @@ module Resque
|
|
26
26
|
end
|
27
27
|
end
|
28
28
|
end
|
29
|
+
|
30
|
+
# Given a word with dashes, returns a camel cased version of it.
|
31
|
+
#
|
32
|
+
# classify('job-name') # => 'JobName'
|
33
|
+
def classify(dashed_word)
|
34
|
+
dashed_word.split('-').each { |part| part[0] = part[0].chr.upcase }.join
|
35
|
+
end
|
36
|
+
|
37
|
+
# Given a camel cased word, returns the constant it represents
|
38
|
+
#
|
39
|
+
# constantize('JobName') # => JobName
|
40
|
+
def constantize(camel_cased_word)
|
41
|
+
camel_cased_word = camel_cased_word.to_s
|
42
|
+
|
43
|
+
if camel_cased_word.include?('-')
|
44
|
+
camel_cased_word = classify(camel_cased_word)
|
45
|
+
end
|
46
|
+
|
47
|
+
names = camel_cased_word.split('::')
|
48
|
+
names.shift if names.empty? || names.first.empty?
|
49
|
+
|
50
|
+
constant = Object
|
51
|
+
names.each do |name|
|
52
|
+
constant = constant.const_get(name) || constant.const_missing(name)
|
53
|
+
end
|
54
|
+
constant
|
55
|
+
end
|
29
56
|
end
|
30
|
-
end
|
57
|
+
end
|
data/lib/resque_unit/resque.rb
CHANGED
data/test/resque_unit_test.rb
CHANGED
@@ -12,6 +12,7 @@ class ResqueUnitTest < Test::Unit::TestCase
|
|
12
12
|
setup { Resque.enqueue(MediumPriorityJob) }
|
13
13
|
should "pass the assert_queued(job) assertion" do
|
14
14
|
assert_queued(MediumPriorityJob)
|
15
|
+
assert_job_created(MediumPriorityJob.queue, MediumPriorityJob)
|
15
16
|
assert_equal 1, Resque.queue(MediumPriorityJob.queue).length
|
16
17
|
end
|
17
18
|
end
|
@@ -361,4 +362,20 @@ class ResqueUnitTest < Test::Unit::TestCase
|
|
361
362
|
end
|
362
363
|
end
|
363
364
|
|
365
|
+
context "A job that is created using Resque::Job.create" do
|
366
|
+
should "be queued" do
|
367
|
+
assert_nothing_raised do
|
368
|
+
Resque::Job.create(:my_custom_queue, "LowPriorityJob", "arg1", "arg2")
|
369
|
+
assert_job_created(:my_custom_queue, LowPriorityJob, ["arg1", "arg2"])
|
370
|
+
end
|
371
|
+
end
|
372
|
+
|
373
|
+
should "queue a job with a dasherized name" do
|
374
|
+
assert_nothing_raised do
|
375
|
+
Resque::Job.create(:my_custom_queue, "low-priority-job", "arg1", "arg2")
|
376
|
+
assert_job_created(:my_custom_queue, LowPriorityJob, ["arg1", "arg2"])
|
377
|
+
end
|
378
|
+
end
|
379
|
+
end
|
380
|
+
|
364
381
|
end
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 3
|
8
|
-
-
|
9
|
-
version: 0.3.
|
8
|
+
- 6
|
9
|
+
version: 0.3.6
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Justin Weiss
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2011-
|
17
|
+
date: 2011-04-11 00:00:00 -07:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -95,7 +95,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
95
95
|
requirements:
|
96
96
|
- - ">="
|
97
97
|
- !ruby/object:Gem::Version
|
98
|
-
hash: -
|
98
|
+
hash: -549847167591292216
|
99
99
|
segments:
|
100
100
|
- 0
|
101
101
|
version: "0"
|
@@ -104,7 +104,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
104
104
|
requirements:
|
105
105
|
- - ">="
|
106
106
|
- !ruby/object:Gem::Version
|
107
|
-
hash: -
|
107
|
+
hash: -549847167591292216
|
108
108
|
segments:
|
109
109
|
- 0
|
110
110
|
version: "0"
|