Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better error message for "I follow the link in the email" #173

Closed
makmic opened this issue Jun 10, 2021 · 0 comments
Closed

Better error message for "I follow the link in the email" #173

makmic opened this issue Jun 10, 2021 · 0 comments
Assignees

Comments

@makmic
Copy link
Member

makmic commented Jun 10, 2021

The current implementation of the mentioned step is missing a safeguard if paths is empty, i.e. when no link has been found in the mail. It is quite hard to debug as visit nil will trigger an exception somewhere else.

# Please note that this step will only follow HTTP and HTTPS links.
# Other links (such as mailto: or ftp:// links) are ignored.
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((?: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) }.compact.map { |match| match[1] }
  else
    mail_body = MailFinder.email_text_body(mail).to_s
    mail_body.scan(url_pattern).flatten(1)
  end

  visit paths[index]
end.overridable

I'd love to see a better error message in this case

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants