Last active
December 11, 2015 18:58
-
-
Save trshafer/4645406 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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