From ca2046dcfd593264644ae9d4141d8365836c297a Mon Sep 17 00:00:00 2001 From: Pablo Brasero Date: Mon, 23 Mar 2026 09:43:02 +0000 Subject: [PATCH] Strengthen negative assertions --- test/jobs/trace_importer_job_test.rb | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/test/jobs/trace_importer_job_test.rb b/test/jobs/trace_importer_job_test.rb index cb2995a7a..ccfb1c8ce 100644 --- a/test/jobs/trace_importer_job_test.rb +++ b/test/jobs/trace_importer_job_test.rb @@ -47,15 +47,15 @@ class TraceImporterJobTest < ActiveJob::TestCase def test_error_notification # Check that the user gets a failure notification when something goes badly wrong trace = create(:trace) - trace.stub(:import, -> { raise }) do + trace.stub(:import, -> { raise "Test Exception" }) do TraceImporterJob.perform_now(trace) end email = ActionMailer::Base.deliveries.last assert_equal trace.user.email, email.to[0] assert_match(/failure/, email.subject) - assert_no_match(/Start tag expected/, email.text_part.body.to_s, "should not include parser error") - assert_match(%r{jobs/trace_importer_job\.rb}, email.text_part.body.to_s, "should include stack backtrace") + assert_match(/Test Exception/, email.text_part.body.to_s, "should show the exception message") + assert_exception_backtrace(email) ActionMailer::Base.deliveries.clear end @@ -70,7 +70,7 @@ class TraceImporterJobTest < ActiveJob::TestCase assert_equal trace.user.email, email.to[0] assert_match(/failure/, email.subject) assert_match(/Fatal error:/, email.text_part.body.to_s, "should include parser error") - assert_no_match(%r{jobs/trace_importer_job\.rb}, email.text_part.body.to_s, "should not include stack backtrace") + assert_no_exception_backtrace(email) ActionMailer::Base.deliveries.clear end @@ -85,8 +85,22 @@ class TraceImporterJobTest < ActiveJob::TestCase assert_equal trace.user.email, email.to[0] assert_match(/failure/, email.subject) assert_match(/Fatal error:/, email.text_part.body.to_s, "should include parser error") - assert_no_match(%r{jobs/trace_importer_job\.rb}, email.text_part.body.to_s, "should not include stack backtrace") + assert_no_exception_backtrace(email) ActionMailer::Base.deliveries.clear end + + private + + def exception_backtrace_matcher + %r{jobs/trace_importer_job\.rb} + end + + def assert_exception_backtrace(email) + assert_match(exception_backtrace_matcher, email.text_part.body.to_s, "should include stack backtrace") + end + + def assert_no_exception_backtrace(email) + assert_no_match(exception_backtrace_matcher, email.text_part.body.to_s, "should not include stack backtrace") + end end -- 2.39.5