diff options
author | George Claghorn <george.claghorn@gmail.com> | 2015-01-08 09:39:01 -0500 |
---|---|---|
committer | George Claghorn <george.claghorn@gmail.com> | 2015-01-08 09:39:01 -0500 |
commit | 91e31e82feaf0ba7609c02b1a3508f0506214404 (patch) | |
tree | 4b654bf658855cf61a6c532cb64f85ba0841e24a /activejob | |
parent | a22a653c293cc5d378d0bfdd595ad60603c5608d (diff) | |
download | rails-91e31e82feaf0ba7609c02b1a3508f0506214404.tar.gz rails-91e31e82feaf0ba7609c02b1a3508f0506214404.tar.bz2 rails-91e31e82feaf0ba7609c02b1a3508f0506214404.zip |
Add :only option to assert_no_enqueued_jobs
Diffstat (limited to 'activejob')
-rw-r--r-- | activejob/lib/active_job/test_helper.rb | 12 | ||||
-rw-r--r-- | activejob/test/cases/test_helper_test.rb | 19 |
2 files changed, 29 insertions, 2 deletions
diff --git a/activejob/lib/active_job/test_helper.rb b/activejob/lib/active_job/test_helper.rb index 0d895a17db..d18656e398 100644 --- a/activejob/lib/active_job/test_helper.rb +++ b/activejob/lib/active_job/test_helper.rb @@ -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. diff --git a/activejob/test/cases/test_helper_test.rb b/activejob/test/cases/test_helper_test.rb index 21fe3db148..f34638e7d8 100644 --- a/activejob/test/cases/test_helper_test.rb +++ b/activejob/test/cases/test_helper_test.rb @@ -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 |