Skip to content

Commit

Permalink
Handle shadowed jobs.
Browse files Browse the repository at this point in the history
  • Loading branch information
stephencelis committed Nov 2, 2010
1 parent 1ed9ae9 commit 62b457c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lib/resque_unit/assertions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ def assert_queued(klass, args = nil, message = nil, &block)
queue_name = Resque.queue_for(klass)

queue = if block_given?
snapshot = Resque.queue(queue_name).dup
snapshot = Resque.size(queue_name)
yield
Resque.queue(queue_name) - snapshot
Resque.queue(queue_name)[snapshot..-1]
else
Resque.queue(queue_name)
end
Expand All @@ -30,9 +30,9 @@ def assert_not_queued(klass = nil, args = nil, message = nil, &block)
queue_name = Resque.queue_for(klass)

queue = if block_given?
snapshot = Resque.queue(queue_name).dup
snapshot = Resque.size(queue_name)
yield
Resque.queue(queue_name) - snapshot
Resque.queue(queue_name)[snapshot..-1]
else
Resque.queue(queue_name)
end
Expand Down
16 changes: 16 additions & 0 deletions test/resque_unit_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,13 @@ def setup
end
end

should "pass the assert_queued(job) assertion when queued and not in block" do
Resque.enqueue(HighPriorityJob)
assert_queues(HighPriorityJob) do
Resque.enqueue(HighPriorityJob)
end
end

should "fail the assert_queued(job) assertion when not queued in block" do
Resque.enqueue(LowPriorityJob)
assert_raise Test::Unit::AssertionFailedError do
Expand All @@ -88,6 +95,15 @@ def setup
end
end

should "fail the assert_not_queued(job) assertion when queued and not in block" do
assert_raise Test::Unit::AssertionFailedError do
Resque.enqueue(LowPriorityJob)
assert_not_queued(LowPriorityJob) do
Resque.enqueue(LowPriorityJob)
end
end
end

should "pass the assert_nothing_queued assertion when nothing queued in block" do
Resque.enqueue(LowPriorityJob)
assert_nothing_queued do
Expand Down

0 comments on commit 62b457c

Please sign in to comment.