Testing Mailers
Learn about testing mailers functionalities and how to write the test for emails and make them pass.
Testing mailers functionalities
Testing Rails mailers involves the following two separate bits of functionality:
- To specify whether the email gets sent as a result of some action.
- To specify that email’s contents. Specifying whether the email gets sent often starts as part of a request or system test while specifying the content has a lot in common with view testing. The somewhat indirect nature of the Rails ActionMailer makes testing email less obvious than it might be, but it’s not hard. We’ll also look at a third-party library that makes email testing easier.
Example
For example, we want to send an email in the project-management system when a task is marked as complete. We don’t have a user model yet (we’ll talk about users in this system when we get to the chapter “Testing for Security”), so let’s assume for the moment that all the emails go to some common audit or monitoring address.
At this point, we have one of those weird, ...