@@ -62,14 +62,64 @@ Feature: have_enqueued_mail matcher
6262 expect {
6363 MyMailer.signup('user').deliver_later
6464 }.to have_enqueued_mail(MyMailer, :signup).with('user')
65+ end
66+ end
67+ """
68+ When I run `rspec spec/mailers/my_mailer_spec.rb`
69+ Then the examples should all pass
70+
71+ Scenario : Parameterize the mailer
72+ Given a file named "app/mailers/my_mailer.rb" with:
73+ """ruby
74+ class MyMailer < ApplicationMailer
75+
76+ def signup(user = nil)
77+ @user = user
78+
79+ 80+ end
81+ end
82+ """
83+ Given a file named "spec/mailers/my_mailer_spec.rb" with:
84+ """ruby
85+ require "rails_helper"
86+
87+ RSpec.describe MyMailer do
88+ it "matches with enqueued mailer" do
89+ ActiveJob::Base.queue_adapter = :test
6590 # Works with named parameters
6691 expect {
67- MyMailer.with('foo' => 'bar').signup.deliver_later
68- }.to have_enqueued_mail(MyMailer, :signup).with('foo' => 'bar')
92+ MyMailer.with(foo: 'bar').signup.deliver_later
93+ }.to have_enqueued_mail(MyMailer, :signup).with(foo: 'bar')
94+ end
95+ end
96+ """
97+ When I run `rspec spec/mailers/my_mailer_spec.rb`
98+ Then the examples should all pass
99+
100+ Scenario : Parameterize and pass an argument to the mailer
101+ Given a file named "app/mailers/my_mailer.rb" with:
102+ """ruby
103+ class MyMailer < ApplicationMailer
104+
105+ def signup(user = nil)
106+ @user = user
107+
108+ 109+ end
110+ end
111+ """
112+ Given a file named "spec/mailers/my_mailer_spec.rb" with:
113+ """ruby
114+ require "rails_helper"
115+
116+ RSpec.describe MyMailer do
117+ it "matches with enqueued mailer" do
118+ ActiveJob::Base.queue_adapter = :test
69119 # Works also with both, named parameters match first argument
70120 expect {
71121 MyMailer.with('foo' => 'bar').signup('user').deliver_later
72- }.to have_enqueued_mail(MyMailer, :signup).with({' foo' => 'bar'}, 'user')
122+ }.to have_enqueued_mail(MyMailer, :signup).with({foo: 'bar'}, 'user')
73123 end
74124 end
75125 """
0 commit comments