mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Add :only option to assert_no_enqueued_jobs
This commit is contained in:
parent
a22a653c29
commit
91e31e82fe
2 changed files with 29 additions and 2 deletions
|
@ -79,11 +79,19 @@ module ActiveJob
|
|||
# end
|
||||
# end
|
||||
#
|
||||
# It can be asserted that no jobs of a specific kind are enqueued:
|
||||
#
|
||||
# def test_no_logging
|
||||
# assert_no_enqueued_jobs only: LoggingJob do
|
||||
# HelloJob.perform_later('jeremy')
|
||||
# end
|
||||
# end
|
||||
#
|
||||
# Note: This assertion is simply a shortcut for:
|
||||
#
|
||||
# assert_enqueued_jobs 0, &block
|
||||
def assert_no_enqueued_jobs(&block)
|
||||
assert_enqueued_jobs 0, &block
|
||||
def assert_no_enqueued_jobs(only: nil, &block)
|
||||
assert_enqueued_jobs 0, only: only, &block
|
||||
end
|
||||
|
||||
# Asserts that the number of performed jobs matches the given number.
|
||||
|
|
|
@ -127,6 +127,25 @@ class EnqueuedJobsTest < ActiveJob::TestCase
|
|||
assert_match(/1 .* but 2/, error.message)
|
||||
end
|
||||
|
||||
def test_assert_no_enqueued_jobs_with_only_option
|
||||
assert_nothing_raised do
|
||||
assert_no_enqueued_jobs only: HelloJob do
|
||||
LoggingJob.perform_later
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def test_assert_no_enqueued_jobs_with_only_option_failure
|
||||
error = assert_raise ActiveSupport::TestCase::Assertion do
|
||||
assert_no_enqueued_jobs only: HelloJob do
|
||||
HelloJob.perform_later('jeremy')
|
||||
LoggingJob.perform_later
|
||||
end
|
||||
end
|
||||
|
||||
assert_match(/0 .* but 1/, error.message)
|
||||
end
|
||||
|
||||
def test_assert_enqueued_job
|
||||
assert_enqueued_with(job: LoggingJob, queue: 'default') do
|
||||
LoggingJob.set(wait_until: Date.tomorrow.noon).perform_later
|
||||
|
|
Loading…
Reference in a new issue