testing mailers in rspec
Asked Answered
M

2

6

Is there no simple way to do the equivalent of response.should render_template(: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?

Mccullough answered 22/4, 2011 at 23:45 Comment(0)
O
3

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.

October answered 22/4, 2011 at 23:56 Comment(1)
Actually... close enough, I guess. Your answer addresses the title of my question, just not exactly what I was looking for (was looking for a render_template assertion helper in mailer specs). But this is still good enough to get most of the way there.Mccullough
U
0
    # 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
Ure answered 12/1, 2021 at 7:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.