Most websites that authenticate users require some form of user account self-management. Users need to register with e-mail and password, verify their e-mail address, and to occasionally reset their e-mail and password.
I like to delegate this to other services with OpenID and OAuth, but not all clients agree to delegate ownership of their customers' authentication records.
So I'm often stuck with implementing these boilerplace features yet again, each of the above use-cases require sending out e-mails to confirm or facilitate. Testing this can be a pain-in-the-butt.
Fortunately, Mikel Lindsaar's Mail gem has a simple and effective way to store and not send e-mails in order to facilitate test scripts.
Mail::TestMailer
Mail.defaults do
delivery_method :test
end
# send a few mails ...
Mail::TestMailer.deliveries.is_a? Array # ==> true
Mail::TestMailer.deliveries.first.is_a? Mail::Message # ==> true
I want to take this a step further so that I can verify that mail got sent to the right people in the right order:
require 'mail'
require 'mail-store-agent'
Mail.defaults do
delivery_method :test
end
Mail::TestMailer.deliveries = MailStoreAgent.new
# send some mail to [email protected], and then ...
Mail::TestMailer.deliveries.get('[email protected]').is_a? Mail::Message # or nil
mail-store-agent.gem by Lawrence Siden is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.
Based on a work at github.com.- Ruby License