Skip to content

Commit

Permalink
assert_queued_at_with_queue追加
Browse files Browse the repository at this point in the history
  • Loading branch information
hsato23 committed Oct 23, 2024
1 parent eca03b2 commit 5f227e2
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
12 changes: 9 additions & 3 deletions lib/resque_unit_without_mock/scheduler_assertions.rb
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
module ResqueUnitWithoutMock::SchedulerAssertions
def assert_queued_at(expected_timestamp, klass)
queue = Resque.queue_for(klass)
assert_queued_at_with_queue(Resque.queue_for(klass), expected_timestamp, klass)
end

def assert_not_queued_at(expected_timestamp, klass)
assert_not_queued_at_with_queue(Resque.queue_for(klass), expected_timestamp, klass)
end

def assert_queued_at_with_queue(queue, expected_timestamp, klass)
result = Resque.enqueue_ats(queue).detect { |hash| hash[:timestamp] <= expected_timestamp && hash[:klass] == klass }
assert(
result,
"#{klass} should have been queued in #{Resque.enqueue_ats(queue)} before #{expected_timestamp}"
)
end

def assert_not_queued_at(expected_timestamp, klass)
queue = Resque.queue_for(klass)
def assert_not_queued_at_with_queue(queue, expected_timestamp, klass)
result = Resque.enqueue_ats(queue).detect { |hash| hash[:timestamp] <= expected_timestamp && hash[:klass] == klass }
assert(
!result,
Expand Down
14 changes: 13 additions & 1 deletion test/resque_unit_without_mock/scheduler_assertions_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def test_assert_queued_at
assert_queued_at(Time.new(2011,11,11,0,0,3), PrintJob)
end

def test_assert_queued_at_with_queue
def test_assert_queued_at_with_class_defined_queue
# |=> queued!!
# | |\\|\\\\\\\\
# 1 2 3
Expand All @@ -41,4 +41,16 @@ def test_assert_queued_at_with_queue
assert_queued_at(Time.new(2011,11,11,0,0,2), PrintJob)
assert_queued_at(Time.new(2011,11,11,0,0,3), PrintJob)
end

def test_assert_queued_at_with_queue
# |=> queued!!
# | |\\|\\\\\\\\
# 1 2 3
assert_not_queued_at_with_queue(:urgent, Time.new(2011,11,11,0,0,2), PrintJob)
assert_not_queued_at_with_queue(:urgent, Time.new(2011,11,11,0,0,3), PrintJob)
Resque.enqueue_at_with_queue(:urgent, Time.new(2011,11,11,0,0,2), PrintJob)
assert_not_queued_at_with_queue(:urgent, Time.new(2011,11,11,0,0,1), PrintJob)
assert_queued_at_with_queue(:urgent, Time.new(2011,11,11,0,0,2), PrintJob)
assert_queued_at_with_queue(:urgent, Time.new(2011,11,11,0,0,3), PrintJob)
end
end

0 comments on commit 5f227e2

Please sign in to comment.