Skip to content

Commit 1ecee28

Browse files
committed
add readme for mailer specs
1 parent 5fcd2fd commit 1ecee28

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

README.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,36 @@ gem "capybara"
287287
For more information, see the [cucumber scenarios for feature
288288
specs](https://www.relishapp.com/rspec/rspec-rails/v/3-4/docs/feature-specs/feature-spec).
289289

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+
290320
## View specs
291321

292322
View specs default to residing in the `spec/views` folder. Tagging any context

features/mailer_specs/README.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
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

0 commit comments

Comments
 (0)