在rspec中测试邮件程序

时间:2011-04-22 23:45:45

标签: actionmailer rspec2

在邮件程序规范中,没有简单的方法可以使用response.should render_template(:foo)吗?这就是我想要做的事情:

  

mail.should render_template(:welcome)

这么多问题吗?我是否陷入了heredocs的黑暗时代,或者手动阅读灯具来匹配?

2 个答案:

答案 0 :(得分:3)

您是否尝试过查看email-spec。它没有确切的语法,但它用于测试发送电子邮件的各个方面。

答案 1 :(得分: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