77module RSpec
88 module Rails
99 module Matchers
10- # rubocop: disable Metrics/ClassLength
1110 # Matcher class for `have_enqueued_mail`. Should not be instantiated directly.
1211 #
1312 # @private
@@ -91,7 +90,7 @@ def arguments_match?(job)
9190
9291 def process_arguments ( job , given_mail_args )
9392 # Old matcher behavior working with all builtin classes but ActionMailer::MailDeliveryJob
94- return given_mail_args unless defined? ( ActionMailer :: MailDeliveryJob ) && job [ :job ] <= ActionMailer :: MailDeliveryJob
93+ return given_mail_args if use_given_mail_args? ( job )
9594
9695 # If matching args starts with a hash and job instance has params match with them
9796 if given_mail_args . first . is_a? ( Hash ) && job [ :args ] [ 3 ] [ 'params' ] . present?
@@ -101,6 +100,13 @@ def process_arguments(job, given_mail_args)
101100 end
102101 end
103102
103+ def use_given_mail_args? ( job )
104+ return true if FeatureCheck . has_action_mailer_parameterized? && job [ :job ] <= ActionMailer ::Parameterized ::DeliveryJob
105+ return false if FeatureCheck . ruby_3_1?
106+
107+ !( FeatureCheck . has_action_mailer_unified_delivery? && job [ :job ] <= ActionMailer ::MailDeliveryJob )
108+ end
109+
104110 def base_mailer_args
105111 [ mailer_class_name , @method_name . to_s , MAILER_JOB_METHOD ]
106112 end
@@ -143,13 +149,20 @@ def mail_job_message(job)
143149 mailer_args = deserialize_arguments ( job ) [ 3 ..-1 ]
144150 mailer_args = mailer_args . first [ :args ] if unified_mail? ( job )
145151 msg_parts = [ ]
146- msg_parts << "with #{ mailer_args } " if mailer_args . any?
152+ display_args = display_mailer_args ( mailer_args )
153+ msg_parts << "with #{ display_args } " if display_args . any?
147154 msg_parts << "on queue #{ job [ :queue ] } " if job [ :queue ] && job [ :queue ] != 'mailers'
148155 msg_parts << "at #{ Time . at ( job [ :at ] ) } " if job [ :at ]
149156
150157 "#{ mailer_method } #{ msg_parts . join ( ', ' ) } " . strip
151158 end
152159
160+ def display_mailer_args ( mailer_args )
161+ return mailer_args unless mailer_args . first . is_a? ( Hash ) && mailer_args . first . key? ( :args )
162+
163+ mailer_args . first [ :args ]
164+ end
165+
153166 def legacy_mail? ( job )
154167 RSpec ::Rails ::FeatureCheck . has_action_mailer_legacy_delivery_job? && job [ :job ] <= ActionMailer ::DeliveryJob
155168 end
@@ -162,7 +175,6 @@ def unified_mail?(job)
162175 RSpec ::Rails ::FeatureCheck . has_action_mailer_unified_delivery? && job [ :job ] <= ActionMailer ::MailDeliveryJob
163176 end
164177 end
165- # rubocop: enable Metrics/ClassLength
166178
167179 # @api public
168180 # Passes if an email has been enqueued inside block.
0 commit comments