@@ -62,14 +62,64 @@ Feature: have_enqueued_mail matcher
62
62
expect {
63
63
MyMailer.signup('user').deliver_later
64
64
}.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
65
90
# Works with named parameters
66
91
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
69
119
# Works also with both, named parameters match first argument
70
120
expect {
71
121
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')
73
123
end
74
124
end
75
125
"""
0 commit comments