Asserting on plain text email content
The text part of a message, exactly as sent. Simpler to assert on than HTML, and the part most transactional senders get wrong.
How it works
body_text is the plain text alternative of the message. Deliverability tools penalise senders who ship HTML with no text part, so asserting that this field exists and reads properly is a real test, not a formality.
Assert on the copy
Whitespace in email bodies is unreliable — normalise before comparing exact strings.
msg = inbox.latest()
assert "reset your password" in msg.text.lower()
assert msg.text.strip(), "the message shipped without a text part"
Both parts, one message
A well-formed transactional email carries text and HTML. Assert on both when the template is what you are testing.
assert msg.text, "missing plain text part"
assert msg.html, "missing HTML part"
See also
HTML content
Check the rendered half of a message: the HTML body is delivered exactly as it arrived, so you can assert on markup, buttons and merge fields.
One-time codesMailFlat pulls the verification code out of the message for you and hands it over as a field, so your test never runs a regex against an email body.
Message propertiesThe envelope around the body: who sent it, exactly which address it reached, what the subject line said and when it landed.