testing mailers in rspec
Is there no simple way to do the equivalent of response.should render_templa开发者_如何学Gote(:foo)
in a mailer spec? Here's what I want to do:
mail.should render_template(:welcome)
Is that so much to ask? Am I stuck in the dark ages of heredocs or manually reading fixtures in to match against?
Have you tried looking at email-spec. It doesn't have the exact syntax but it is used for testing various aspects of sending emails.
# IMPORTANT!
# must copy https://gitlab.com/gitlab-org/gitlab/-/blob/master/spec/support/helpers/next_instance_of.rb
it 'renders foo_mail' do
allow_next_instance_of(described_class) do |mailer|
allow(mailer).to receive(:render_to_body).and_wrap_original do |m, options|
expect(options[:template]).to eq('foo_mail')
m.call(options)
end
end
body = subject.body.encoded
end
精彩评论