assert_enqueued_jobs
- 1.0.0
- 1.1.6
- 1.2.6
- 2.0.3
- 2.1.0
- 2.2.1
- 2.3.8
- 3.0.0
- 3.0.9
- 3.1.0
- 3.2.1
- 3.2.8
- 3.2.13
- 4.0.2
- 4.1.8
- 4.2.1 (0)
- 4.2.7 (0)
- 4.2.9 (0)
- 5.0.0.1 (36)
- 5.1.7 (38)
- 5.2.3 (38)
- 6.0.0 (37)
- 6.1.3.1 (0)
- 6.1.7.7 (0)
- 7.0.0 (0)
- 7.1.3.2 (0)
- 7.1.3.4 (0)
- What's this?
assert_enqueued_jobs(number, only: nil, except: nil, queue: nil, &block)
public
Asserts that the number of enqueued jobs matches the given number.
def test_jobs assert_enqueued_jobs 0 HelloJob.perform_later('david') assert_enqueued_jobs 1 HelloJob.perform_later('abdelkader') assert_enqueued_jobs 2 end
If a block is passed, asserts that the block will cause the specified number of jobs to be enqueued.
def test_jobs_again assert_enqueued_jobs 1 do HelloJob.perform_later('cristian') end assert_enqueued_jobs 2 do HelloJob.perform_later('aaron') HelloJob.perform_later('rafael') end end
Asserts the number of times a specific job was enqueued by passing :only option.
def test_logging_job assert_enqueued_jobs 1, only: LoggingJob do LoggingJob.perform_later HelloJob.perform_later('jeremy') end end
Asserts the number of times a job except specific class was enqueued by passing :except option.
def test_logging_job assert_enqueued_jobs 1, except: HelloJob do LoggingJob.perform_later HelloJob.perform_later('jeremy') end end
:only and :except options accepts Class, Array of Class or Proc. When passed a Proc, a hash containing the job’s class and it’s argument are passed as argument.
Asserts the number of times a job is enqueued to a specific queue by passing :queue option.
def test_logging_job assert_enqueued_jobs 2, queue: 'default' do LoggingJob.perform_later HelloJob.perform_later('elfassy') end end