DEV Community

Masato Ohba
Masato Ohba

Posted on • Edited on

3 2

Generate email list automatically with automaildoc

Hello, diligent developers who manage systems to send emails to somewhere. In this article, I'd like to introduce a Ruby gem named automaildoc, which generates mail list from RSpec automatically.

image

How to use

After installing the gem, run AUTOMAILDOC = 1 rspec from the command line to generate HTML to list the mail. Easy!

Let me elaborate a bit for beginners.

Add this line to your application's Gemfile:

gem 'automaildoc', group: :test
Enter fullscreen mode Exit fullscreen mode

And then execute:

$ bundle
Enter fullscreen mode Exit fullscreen mode

Add an automaildoc tag to your mail spec. (Don't you have it? Then it's an exact chance to write them right now!)

RSpec.describe 'Sign up mail', automaildoc: true do
  let!(:user) { create(:user) }
  let!(:mail) { SignupMailer.mail(user) }

  it 'should send to a user' do
    expect(mail.to).to eq user
  end
end
Enter fullscreen mode Exit fullscreen mode

Run Rspec test with AUTOMAILDOC=1.

$ AUTOMAILDOC=1 bundle exec rspec
Enter fullscreen mode Exit fullscreen mode

That's it. Then automaildoc generates an HTML file to ./doc/mails. The file should be what you've wanted.

Background of automaildoc

Have you received such inquiries from stakeholders like product managers, a business side, customer support, etc.?

"May I confirm emails sent from our system for legal/brand check?"

"Can you show the text of a similar past email to think of the sentence of the newly sent email?"

Then developers respond each time by checking code or I18n translation files. I have experienced such a situation many times.

However, due to the A/B test and CS request, a content of an email is frequently updated. A total number of emails will increase or decrease without noticing during daily development. Besides, there is also a problem that even if the mail is same, it varies depending on the context or condition. I finally found the task repeatable, annoying, and not more comfortable than I'd expect.

As a solution to this problem, my colleague gave me an idea that it would be convenient to generate from RSpec automatically like autodoc. After that, when I received a request like "I want to see email list" again, then I remembered this and tried it with great force.


I hope this article and gem would be helpful for you too.

Sentry blog image

How to reduce TTFB

In the past few years in the web dev world, we’ve seen a significant push towards rendering our websites on the server. Doing so is better for SEO and performs better on low-powered devices, but one thing we had to sacrifice is TTFB.

In this article, we’ll see how we can identify what makes our TTFB high so we can fix it.

Read more

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay