Вот assert_select_email
от образцового Redmine:
assert_select_email do
assert_select 'a[href^=?]', 'http://localhost:3000/settings'
end
Все программисты Rails должны изучать литературу, такую как Redmine, чтобы выучить много полезных трюков.
# 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
#
# 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
def assert_select_email(&block)
deliveries = ActionMailer::Base.deliveries
assert !deliveries.empty?, "No e-mail in delivery list"
deliveries.each do |delivery|
(delivery.parts.empty? ? [delivery] : delivery.parts).each do |part|
if part["Content-Type"].to_s =~ /^text\/html\W/
root = Nokogiri::HTML::DocumentFragment.parse(part.body.to_s)
assert_select root, ":root", &block
end
end
end
end