Skip to content

Commit 387fe76

Browse files
authored
Merge pull request #2793 from davidrunger/update-have-enqueued-mail-method-name
Update method name in HaveEnqueuedMail (job_match? to job_matches?)
2 parents f34754e + 49fce99 commit 387fe76

File tree

3 files changed

+16
-8
lines changed

3 files changed

+16
-8
lines changed

Changelog.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
### Development
22
[Full Changelog](https://github.com/rspec/rspec-rails/compare/v7.0.1...main)
33

4+
Bug Fixes:
5+
6+
* Fix `have_enqueued_mail` wrongful failure when expecting no enqueued mail but
7+
a non-mail job is enqueued. (David Runger, #2793)
8+
49
### 7.0.1 / 2024-09-03
510
[Full Changelog](https://github.com/rspec/rspec-rails/compare/v7.0.0...v7.0.1)
611

lib/rspec/rails/matchers/have_enqueued_mail.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ def mailer_class_name
7272
@mailer_class ? @mailer_class.name : 'ActionMailer::Base'
7373
end
7474

75-
def job_match?(job)
75+
def job_matches?(job)
7676
legacy_mail?(job) || parameterized_mail?(job) || unified_mail?(job)
7777
end
7878

@@ -123,7 +123,7 @@ def check_active_job_adapter
123123

124124
def unmatching_mail_jobs
125125
@unmatching_jobs.select do |job|
126-
job_match?(job)
126+
job_matches?(job)
127127
end
128128
end
129129

spec/rspec/rails/matchers/have_enqueued_mail_spec.rb

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ class AnotherTestMailer < ActionMailer::Base
2020
def test_email; end
2121
end
2222

23+
class NonMailerJob < ActiveJob::Base
24+
def perform; end
25+
end
26+
2327
if RSpec::Rails::FeatureCheck.has_action_mailer_unified_delivery?
2428
class UnifiedMailer < ActionMailer::Base
2529
self.delivery_job = ActionMailer::MailDeliveryJob
@@ -95,6 +99,10 @@ def test_email; end
9599
expect { }.not_to have_enqueued_email
96100
end
97101

102+
it "passes when negated with 0 arguments and a non-mailer job is enqueued" do
103+
expect { NonMailerJob.perform_later }.not_to have_enqueued_email
104+
end
105+
98106
it "passes when only given mailer argument" do
99107
expect {
100108
TestMailer.test_email.deliver_later
@@ -305,11 +313,6 @@ def test_email; end
305313
end
306314

307315
it "generates a failure message with unmatching enqueued mail jobs" do
308-
non_mailer_job = Class.new(ActiveJob::Base) do
309-
def perform; end
310-
def self.name; "NonMailerJob"; end
311-
end
312-
313316
send_time = Date.tomorrow.noon
314317
queue = 'urgent_mail'
315318

@@ -320,7 +323,7 @@ def self.name; "NonMailerJob"; end
320323

321324
expect {
322325
expect {
323-
non_mailer_job.perform_later
326+
NonMailerJob.perform_later
324327
TestMailer.test_email.deliver_later
325328
TestMailer.email_with_args(3, 4).deliver_later(wait_until: send_time, queue: queue)
326329
}.to have_enqueued_email(TestMailer, :email_with_args).with(1, 2)

0 commit comments

Comments
 (0)