How to check - using rspec - which template is used when creating email? (Rails 3.0.7)

I am trying to write some tests for emails generated using the mailer class using rspec and email_spec (Ruby on Rails 3.0.7)

I would like to check if the layout used to render email is the layout specified in the mailer class.

Any idea on how to do this? I spent 3 hours searching for a solution, but found nothing.

Thanks!

+4
source share
2 answers

(I understand this is a rather late answer. Perhaps you have already found a solution) I will not be able to repeatedly update this answer, but will this page help? It describes how to check if the layout has been rendered. You can make a receive request with parameters (an example here ), and then check if the result displays the layout you want to display.

0
source

This changes a bit, since you really don't check which template was created ...

However, I just wanted to quickly check that the correct letter (possibly) that was created was working - so that was enough for my needs:

# In RSpec: expect(ActionMailer::Base.deliveries.last.subject) .to eq I18n.t("name.of.email.subject") # In MiniTest: assert_equal I18n.t("name.of.email.subject"), ActionMailer::Base.deliveries.last.subject 
0
source

All Articles