From c67c1d9f26b3489f2860e35920cc5a4362c1608d Mon Sep 17 00:00:00 2001 From: Peter Boling Date: Thu, 10 Dec 2015 17:07:03 -0800 Subject: [PATCH 1/2] Fixes #119: Only select Jobs in queue that are for the given Worker class --- README.md | 1 + lib/resque_spec/matchers.rb | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 509bac1..d8ef18d 100644 --- a/README.md +++ b/README.md @@ -476,6 +476,7 @@ Contributors * Ilya Katz (@ilyakatz) : Cleanup README.md for RSpec 3 * (@addbrick) : Compare times as integers in `have_scheduled` matcher * Serious Haircut (@serioushaircut) : Fix ArgumentListMatcher to make it work with any\_args +* Peter Boling (@pboling) : Fix `queue` to return jobs of Worker class specified to correct `size` Copyright ========= diff --git a/lib/resque_spec/matchers.rb b/lib/resque_spec/matchers.rb index b675dc7..b09c8dc 100644 --- a/lib/resque_spec/matchers.rb +++ b/lib/resque_spec/matchers.rb @@ -27,9 +27,12 @@ def in(queue_name) def queue(actual) if @queue_name + # All the Jobs in a queue ResqueSpec.queue_by_name(@queue_name) else - ResqueSpec.queue_for(actual) + # Only the Jobs for the given class (actual) in a queue. + # Why? A single queue can be used by multiple workers. + ResqueSpec.queue_for(actual).select {|queued| queued[:class] == actual.name} end end end From 534f0b2302bf6e6bba06ae3752e83694d9a8c535 Mon Sep 17 00:00:00 2001 From: Peter Boling Date: Thu, 10 Dec 2015 17:12:26 -0800 Subject: [PATCH 2/2] Allow given class to be String or Constant --- lib/resque_spec/matchers.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/resque_spec/matchers.rb b/lib/resque_spec/matchers.rb index b09c8dc..beba433 100644 --- a/lib/resque_spec/matchers.rb +++ b/lib/resque_spec/matchers.rb @@ -32,7 +32,13 @@ def queue(actual) else # Only the Jobs for the given class (actual) in a queue. # Why? A single queue can be used by multiple workers. - ResqueSpec.queue_for(actual).select {|queued| queued[:class] == actual.name} + ResqueSpec.queue_for(actual).select do |queued| + if actual.respond_to?(:name) + queued[:class] == actual.name + else + queued[:class].to_s == actual.to_s + end + end end end end