instance method assert_performed_with

Ruby on Rails 5.1.7

Since v4.2.11.3

Available in: v4.2.11.3 v5.0.7.2 v5.1.7 v5.2.8.1 v6.0.6.1 v6.1.7.10 v7.0.10 v7.1.6 v7.2.3.2 v8.0.5.1 v8.1.3.1 edge

Signature

assert_performed_with(job: nil, args: nil, at: nil, queue: nil)

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

Parameters

job key = nil
args key = nil
at key = nil
queue key = nil
Source
# File activejob/lib/active_job/test_helper.rb, line 286
    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
      serialized_args = serialize_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|
        serialized_args.all? { |key, value| value == in_block_job[key] }
      end
      assert matching_job, "No performed job found with #{expected}"
      instantiate_job(matching_job)
    end

Defined in activejob/lib/active_job/test_helper.rb line 286 · View on GitHub · Improve this page · Find usages on GitHub

Defined in ActiveJob::TestHelper

Type at least 2 characters to search.

Use the arrow keys to navigate results, Enter to open one, Escape to close.

Keyboard shortcuts

/
Focus search
⌘K / Ctrl-K
Command palette
?
This help
Esc
Close