File tree Expand file tree Collapse file tree 2 files changed +56
-0
lines changed Expand file tree Collapse file tree 2 files changed +56
-0
lines changed Original file line number Diff line number Diff line change @@ -287,6 +287,36 @@ gem "capybara"
287
287
For more information, see the [ cucumber scenarios for feature
288
288
specs] ( https://www.relishapp.com/rspec/rspec-rails/v/3-4/docs/feature-specs/feature-spec ) .
289
289
290
+ ## Mailer specs
291
+
292
+ By default Mailer specs reside in the ` spec/mailers ` folder. Adding the metadata
293
+ ` :type => :mailer ` to any context makes its examples be treated as mailer specs.
294
+
295
+ ` ActionMailer::TestCase::Behavior ` is mixed into your mailer specs.
296
+
297
+ ``` ruby
298
+ require " rails_helper"
299
+
300
+ RSpec .describe Notifications , :type => :mailer do
301
+ describe " notify" do
302
+ let(:mail ) { Notifications .signup }
303
+
304
+ it " renders the headers" do
305
+ expect(mail.subject).to eq(" Signup" )
306
+ expect(mail.to).to eq([
" [email protected] " ])
307
+ expect(mail.from).to eq([
" [email protected] " ])
308
+ end
309
+
310
+ it " renders the body" do
311
+ expect(mail.body.encoded).to match(" Hi" )
312
+ end
313
+ end
314
+ end
315
+ ```
316
+
317
+ For more information, see the [ cucumber scenarios for mailer specs
318
+ ] ( https://relishapp.com/rspec/rspec-rails/v/3-4/docs/mailer-specs ) .
319
+
290
320
## View specs
291
321
292
322
View specs default to residing in the ` spec/views ` folder. Tagging any context
Original file line number Diff line number Diff line change
1
+ By default Mailer specs reside in the ` spec/mailers ` folder. Adding the metadata
2
+ ` :type => :mailer ` to any context makes its examples be treated as mailer specs.
3
+
4
+ A mailer spec is a thin wrapper for an ActionMailer::TestCase, and includes all
5
+ of the behavior and assertions that it provides, in addition to RSpec's own
6
+ behavior and expectations.
7
+
8
+ ## Examples
9
+
10
+ require "rails_helper"
11
+
12
+ RSpec.describe Notifications, :type => :mailer do
13
+ describe "notify" do
14
+ let(:mail) { Notifications.signup }
15
+
16
+ it "renders the headers" do
17
+ expect(mail.subject).to eq("Signup")
18
+ expect(mail.to).to eq(["[email protected] "])
19
+ expect(mail.from).to eq(["[email protected] "])
20
+ end
21
+
22
+ it "renders the body" do
23
+ expect(mail.body.encoded).to match("Hi")
24
+ end
25
+ end
26
+ end
You can’t perform that action at this time.
0 commit comments