Open stevepolitodesign opened 1 year ago
I think it would be a nice addition if we added current_email
and email_link
helper methods for testing. Below is are the proposed helper methods inspired from a personal post. Similar to capybara-email
def open_latest_email_for(email_address)
@current_email = ActionMailer::Base.deliveries.reverse.detect do |email|
email.to.include?(email_address)
end
end
def current_email
@current_email ||= ActionMailer::Base.deliveries.last
end
def email_link(email, string)
document = Capybara.string(email.body.to_s)
link = document.find(:link, string)[:href]
localize_link(link)
end
private
def localize_link(link)
uri = URI.parse(link)
if uri.query
"#{uri.path}?#{uri.query}"
else
uri.path
end
end
When writing integration and/or system tests, I want to be able to easily test mailer links so that my developer experience is improved.
Acceptance Criteria