开发者

How to test - with rspec - what template is used when creating an email? (Rails 3.0.7)

开发者 https://www.devze.com 2023-03-19 00:51 出处:网络
I\'m trying to write some tests for 开发者_如何学Cemails generated with a mailer class using rspec and email_spec (Ruby on Rails 3.0.7)

I'm trying to write some tests for 开发者_如何学Cemails generated with a mailer class using rspec and email_spec (Ruby on Rails 3.0.7)

I would like to check if the layout used for rendering the email is the layout that was specified in the mailer class.

Any idea on how to do this? I've spent 3 hours searching for a solution but couldn't find anything.

Thanks!


(I realize this is a pretty late response. You've probably found a solution already) I won't be able to update this answer much, but does this page help? It describes how to check if a layout was rendered. You could make a get request with parameters (example here) then check if the result renders the layout you want it to render.


This is cheating a little bit, since you're not really checking which template got generated...

However, I just wanted to perform a quick sanity check that the right email is (probably) being generated - so this was good 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

精彩评论

暂无评论...
验证码 换一张
取 消