instance method assert_part

Ruby on Rails edge

Since edge

Signature

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_type req
mail opt = last_delivered_mail!
Source
# File actionmailer/lib/action_mailer/test_case.rb, line 111
      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 111 · View on GitHub · Improve this page · Find usages on GitHub

Defined in ActionMailer::TestCase::Behavior

Type at least 2 characters to search.

Use the arrow keys to navigate results, Enter to open one, Escape to close.

Keyboard shortcuts

/
Focus search
⌘K / Ctrl-K
Command palette
?
This help
Esc
Close