"I follow the ... link in the email" should only follow <a> links in HTML e-mails
Closed this issue · 1 comments
foobear commented
The above step from Spreewald scans for any URL-like string and tries to visit it. This is too much for HTML e-mails where it hits xmlns
URLs or similar.
Instead, the step should do something like this:
When /^I follow the (first|second|third)? ?link in the e?mail$/ do |index_in_words|
mail = @mail || ActionMailer::Base.deliveries.last
index = { nil => 0, 'first' => 0, 'second' => 1, 'third' => 2 }[index_in_words]
url_pattern = %r{(?:http|https)://[^/]+([^"'\s\\]*)}
paths = if mail.html_part
dom = Nokogiri::HTML(mail.html_part.body.to_s)
(dom / 'a[href]').map { |a| a['href'].match(url_pattern)[1] }
else
mail_body = MailFinder.email_text_body(mail).to_s
mail_body.scan(url_pattern)[0]
end
visit paths[index]
end
foobear commented
Fixed in Spreewald 2.4.0