instance method assert_select_email

Ruby on Rails 3.0.20

Since v3.0.20 Last seen in v4.1.16

Available in: v3.0.20 v3.1.12 v3.2.22.5 v4.0.13 v4.1.16

Signature

assert_select_email { }

Extracts the body of an email and runs nested assertions on it.

You must enable deliveries for this assertion to work, use:

ActionMailer::Base.perform_deliveries = true

Examples

assert_select_email do
  assert_select "h1", "Email alert"
end

assert_select_email do
  items = assert_select "ol>li"
  items.each do
     # Work with items here...
  end
end

Parameters

block block
Source
# File actionpack/lib/action_dispatch/testing/assertions/selector.rb, line 567
      def assert_select_email(&block)
        deliveries = ActionMailer::Base.deliveries
        assert !deliveries.empty?, "No e-mail in delivery list"

        for delivery in deliveries
          for part in (delivery.parts.empty? ? [delivery] : delivery.parts)
            if part["Content-Type"].to_s =~ /^text\/html\W/
              root = HTML::Document.new(part.body.to_s).root
              assert_select root, ":root", &block
            end
          end
        end
      end

Defined in actionpack/lib/action_dispatch/testing/assertions/selector.rb line 567 · View on GitHub · Improve this page · Find usages on GitHub

Defined in ActionDispatch::Assertions::SelectorAssertions

Type at least 2 characters to search.

↑↓ navigate · open · esc close