class Spreewald::Steps::FollowTheLink

Constants

URL_PATTERN

Public Class Methods

new(mail, index_in_words) click to toggle source
# File lib/steps/follow_the_link.rb, line 20
def initialize(mail, index_in_words)
  @mail = mail
  @index_in_words = index_in_words
end

Public Instance Methods

run() click to toggle source
# File lib/steps/follow_the_link.rb, line 25
def run
  index = { nil => 0, 'first' => 0, 'second' => 1, 'third' => 2 }[@index_in_words]

  paths = if @mail.html_part || body_text_html?
    search_for_links_in_html
  else
    search_for_links_in_plaintext
  end

  if paths[index]
    visit_path paths[index]
  else
    raise NoVisitableLinkFound.new(paths, @index_in_words) unless paths[index]
  end
end

Private Instance Methods

body_text_html?() click to toggle source
# File lib/steps/follow_the_link.rb, line 47
def body_text_html?
  @mail.body.to_s.include? "<html>"
end
visit_path(path) click to toggle source
# File lib/steps/follow_the_link.rb, line 43
def visit_path(path)
  Capybara.visit(path)
end