public Method

SelectorAssertions.assert_select_email(&block)

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

Source Code

# File action_controller/assertions/selector_assertions.rb, line 561
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
      if part["Content-Type"].to_s =~ /^text\/html\W/
        root = HTML::Document.new(part.body).root
        assert_select root, ":root", &block
      end
    end
  end
end
Comments

Have your say
Please use Textile formatting (click here for a cheat sheet). Use <code/> and <pre/> for code samples.
Click here to login with OpenID to to post comments.