Testing ActionMailer multipart emails(text and html version) with RSpec

后端 未结 5 909
灰色年华
灰色年华 2021-01-30 22:06

I\'m currently testing my mailers with RSpec, but I\'ve started setting up multipart emails as described in the Rails Guides here: http://guides.rubyonrails.org/action_mailer_b

5条回答
  •  梦如初夏
    2021-01-30 22:32

    I have done this way, I found it simpler since the content of both emails is gonna be similar except styles and markup.

    context 'When there are no devices' do
      it 'makes sure both HTML and text version emails are sent' do
        expect(mail.body.parts.count).to eq(2)
        # You can even make sure the types of the part are `html` and `text`
      end
    
      it 'does not list any lockboxes to be removed in both types emails' do
        mail.body.parts.each do |part|
          expect(part.body).to include('No devices to remove')
        end
      end
    end
    

提交回复
热议问题