Skip to content

Commit 330b5bd

Browse files
author
Sam Phippen
committed
Fix the mailer generator for rails 5
1 parent 41ecb8b commit 330b5bd

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

lib/generators/rspec/mailer/templates/mailer_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
require "rails_helper"
22

33
<% module_namespacing do -%>
4-
RSpec.describe <%= class_name %>, <%= type_metatag(:mailer) %> do
4+
RSpec.describe <%= class_name %><%= Rails.version.to_f >= 5.0 ? "Mailer" : "" %>, <%= type_metatag(:mailer) %> do
55
<% for action in actions -%>
66
describe "<%= action %>" do
7-
let(:mail) { <%= class_name %>.<%= action %> }
7+
let(:mail) { <%= class_name %><%= Rails.version.to_f >= 5.0 ? "Mailer" : "" %>.<%= action %> }
88
99
it "renders the headers" do
1010
expect(mail.subject).to eq(<%= action.to_s.humanize.inspect %>)

spec/generators/rspec/mailer/mailer_generator_spec.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,12 @@
1313
end
1414
it { is_expected.to exist }
1515
it { is_expected.to contain(/require "rails_helper"/) }
16-
it { is_expected.to contain(/^RSpec.describe Posts, #{type_metatag(:mailer)}/) }
16+
if Rails.version.to_f >= 5.0
17+
# Rails 5 automatically appends Mailer to the provided constant so we do too
18+
it { is_expected.to contain(/^RSpec.describe PostsMailer, #{type_metatag(:mailer)}/) }
19+
else
20+
it { is_expected.to contain(/^RSpec.describe Posts, #{type_metatag(:mailer)}/) }
21+
end
1722
it { is_expected.to contain(/describe "index" do/) }
1823
it { is_expected.to contain(/describe "show" do/) }
1924
end

0 commit comments

Comments
 (0)