module ActiveJob::TestHelper
def assert_enqueued_with(job: nil, args: nil, at: nil, queue: nil)
end
MyJob.set(wait_until: Date.tomorrow.noon).perform_later
assert_enqueued_with(job: MyJob, at: Date.tomorrow.noon) do
end
MyJob.perform_later(1,2,3)
assert_enqueued_with(job: MyJob, args: [1,2,3], queue: 'low') do
def test_assert_enqueued_with
Asserts that the job passed in the block has been enqueued with the given arguments.
def assert_enqueued_with(job: nil, args: nil, at: nil, queue: nil) original_enqueued_jobs_count = enqueued_jobs.count expected = { job: job, args: args, at: at, queue: queue }.compact expected_args = prepare_args_for_assertion(expected) yield in_block_jobs = enqueued_jobs.drop(original_enqueued_jobs_count) matching_job = in_block_jobs.find do |in_block_job| deserialized_job = deserialize_args_for_assertion(in_block_job) expected_args.all? { |key, value| value == deserialized_job[key] } end assert matching_job, "No enqueued job found with #{expected}" instantiate_job(matching_job) end