mirror of https://github.com/rails/rails
Merge pull request #19969 from y-yagi/fix_job_helper_method
match a expected value with message of `assert_equal` in AJ helper methods
This commit is contained in:
commit
4d4950fae9
|
@ -1,3 +1,9 @@
|
|||
* `assert_enqueued_jobs` and `assert_performed_jobs` in block form use the
|
||||
given number as expected value. This makes the error message much easier to
|
||||
understand.
|
||||
|
||||
*y-yagi*
|
||||
|
||||
* A generated job now inherents from `app/jobs/application_job.rb` by default.
|
||||
|
||||
*Jeroen van Baarsen*
|
||||
|
|
|
@ -68,7 +68,7 @@ module ActiveJob
|
|||
original_count = enqueued_jobs_size(only: only)
|
||||
yield
|
||||
new_count = enqueued_jobs_size(only: only)
|
||||
assert_equal original_count + number, new_count, "#{number} jobs expected, but #{new_count - original_count} were enqueued"
|
||||
assert_equal number, new_count - original_count, "#{number} jobs expected, but #{new_count - original_count} were enqueued"
|
||||
else
|
||||
actual_count = enqueued_jobs_size(only: only)
|
||||
assert_equal number, actual_count, "#{number} jobs expected, but #{actual_count} were enqueued"
|
||||
|
@ -164,7 +164,7 @@ module ActiveJob
|
|||
original_count = performed_jobs.size
|
||||
perform_enqueued_jobs(only: only) { yield }
|
||||
new_count = performed_jobs.size
|
||||
assert_equal original_count + number, new_count,
|
||||
assert_equal number, new_count - original_count,
|
||||
"#{number} jobs expected, but #{new_count - original_count} were performed"
|
||||
else
|
||||
performed_jobs_size = performed_jobs.size
|
||||
|
|
|
@ -31,6 +31,17 @@ class EnqueuedJobsTest < ActiveJob::TestCase
|
|||
end
|
||||
end
|
||||
|
||||
def test_assert_enqueued_jobs_message
|
||||
HelloJob.perform_later('sean')
|
||||
e = assert_raises Minitest::Assertion do
|
||||
assert_enqueued_jobs 2 do
|
||||
HelloJob.perform_later('sean')
|
||||
end
|
||||
end
|
||||
assert_match "Expected: 2", e.message
|
||||
assert_match "Actual: 1", e.message
|
||||
end
|
||||
|
||||
def test_assert_enqueued_jobs_with_no_block
|
||||
assert_nothing_raised do
|
||||
HelloJob.perform_later('rafael')
|
||||
|
@ -230,6 +241,17 @@ class PerformedJobsTest < ActiveJob::TestCase
|
|||
end
|
||||
end
|
||||
|
||||
def test_assert_performed_jobs_message
|
||||
HelloJob.perform_later('sean')
|
||||
e = assert_raises Minitest::Assertion do
|
||||
assert_performed_jobs 2 do
|
||||
HelloJob.perform_later('sean')
|
||||
end
|
||||
end
|
||||
assert_match "Expected: 2", e.message
|
||||
assert_match "Actual: 1", e.message
|
||||
end
|
||||
|
||||
def test_assert_performed_jobs_with_no_block
|
||||
assert_nothing_raised do
|
||||
perform_enqueued_jobs do
|
||||
|
|
Loading…
Reference in New Issue