instance method
assert_part
Ruby on Rails edge
Since edgeSignature
assert_part(content_type, mail = last_delivered_mail!)
Assert that a Mail instance has a part matching the content type. If the Mail is multipart, extract and decode the appropriate part. Yield the decoded part to the block.
By default, assert against the last delivered Mail.
“‘ UsersMailer.create(user).deliver_now assert_part :text do |text|
assert_includes text, "Welcome, #{user.email}"
end assert_part :html do |html|
assert_dom html.root, "h1", text: "Welcome, #{user.email}"
end “‘
Assert against a Mail instance when provided
“‘ mail = UsersMailer.create(user) assert_part :text, mail do |text|
assert_includes text, "Welcome, #{user.email}"
end assert_part :html, mail do |html|
assert_dom html.root, "h1", text: "Welcome, #{user.email}"
end “‘
Parameters
-
content_typereq -
mailopt = last_delivered_mail!
Source
# File actionmailer/lib/action_mailer/test_case.rb, line 115
def assert_part(content_type, mail = last_delivered_mail!)
mime_type = Mime[content_type]
part = [*mail.all_parts, mail].find { |part| mime_type.match?(part.mime_type) }
decoder = _decoders[mime_type]
assert_not_nil part, "expected part matching #{mime_type} in #{mail.inspect}"
yield decoder.call(part.decoded) if block_given?
end
Defined in actionmailer/lib/action_mailer/test_case.rb line 115
· View on GitHub
· Improve this page
· Find usages on GitHub
Defined in ActionMailer::TestCase::Behavior