actionmailer on davidchua https://dchua.com/tags/actionmailer/ Recent content in actionmailer on davidchua Hugo -- gohugo.io en-us Tue, 12 Aug 2014 12:22:03 +0800 DRY your ActionMailer::Base.deliveries.clear in RSpec tests https://dchua.com/posts/2014-08-12-dry-your-actionmailer-base.deliveries.clear-in-rspec-tests/ Tue, 12 Aug 2014 12:22:03 +0800 https://dchua.com/posts/2014-08-12-dry-your-actionmailer-base.deliveries.clear-in-rspec-tests/ When testing for mailers, you might need to add the following quite frequently: describe "test mailer" do it "should work" do ActionMailer::Base.deliveries.clear # bunch of other # codes here end end You probably would add them at the start of every test block that tests for ActionMailer. The neater way would be to do this: describe "test mailer", type: :mailer do it "should work" do # bunch of # codes here end end By assigning a mailer_type to the test describe, RSpec will automatically clear the actionmailer deliveries at the start.