Skip to content

Instantly share code, notes, and snippets.

@trshafer
Last active December 11, 2015 18:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save trshafer/4645406 to your computer and use it in GitHub Desktop.
Save trshafer/4645406 to your computer and use it in GitHub Desktop.
RSpec::Matchers.define :have_body_text do |text|
match do |mail|
fail("No body content to check for #{text}") if mail.parts.blank?
assert_mail_text_in_all_parts(mail, text)
end
def assert_mail_text_in_all_parts(mail, text)
mail.parts.all? do |part|
part.body.include?(text)
end
end
failure_message_for_should do |mail|
"expected that #{text} would be included in #{mail_body mail}"
end
failure_message_for_should_not do |mail|
"expected that #{text} would not be included in #{mail_body mail}"
end
description do
"include #{text} in all mail parts"
end
def mail_body mail
mail.parts.inject("") do |string, part|
"\n#{string}#{'=' * 6} #{part.content_type} #{'=' * 6}\n\n#{part.body}\n"
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment