assert_performed_with(job: nil, args: nil, at: nil, queue: nil)
public
Asserts that the job passed in the block has been performed with the given
arguments.
def test_assert_performed_with
assert_performed_with(job: MyJob, args: [1,2,3], queue: 'high') do
MyJob.perform_later(1,2,3)
end
assert_performed_with(job: MyJob, at: Date.tomorrow.noon) do
MyJob.set(wait_until: Date.tomorrow.noon).perform_later
end
end
# File activejob/lib/active_job/test_helper.rb, line 325
def assert_performed_with(job: nil, args: nil, at: nil, queue: nil)
original_performed_jobs_count = performed_jobs.count
expected = { job: job, args: args, at: at, queue: queue }.compact
expected_args = prepare_args_for_assertion(expected)
perform_enqueued_jobs { yield }
in_block_jobs = performed_jobs.drop(original_performed_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 performed job found with #{expected}"
instantiate_job(matching_job)
end