Class: Capybara::Email::Driver

Inherits:
Driver::Base
  • Object
show all
Defined in:
lib/capybara/email/driver.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(email) ⇒ Driver

Returns a new instance of Driver.



4
5
6
# File 'lib/capybara/email/driver.rb', line 4

def initialize(email)
  @email = email
end

Instance Attribute Details

#emailObject (readonly)

Returns the value of attribute email.



2
3
4
# File 'lib/capybara/email/driver.rb', line 2

def email
  @email
end

Instance Method Details

#bodyObject



13
14
15
# File 'lib/capybara/email/driver.rb', line 13

def body
  dom.to_xml
end

#domObject

Nokogiri object for traversing content

Returns:

  • Nokogiri::HTML::Document



47
48
49
# File 'lib/capybara/email/driver.rb', line 47

def dom
  @dom ||= Nokogiri::HTML(source)
end

#find(selector) ⇒ Array<Capybara::Driver::Node> Also known as: find_xpath

Find elements based on given xpath

Parameters:

  • (xpath string)

Returns:

  • (Array<Capybara::Driver::Node>)


56
57
58
# File 'lib/capybara/email/driver.rb', line 56

def find(selector)
  dom.xpath(selector).map { |node| Capybara::Email::Node.new(self, node) }
end

#follow(url) ⇒ Object



8
9
10
11
# File 'lib/capybara/email/driver.rb', line 8

def follow(url)
  url = URI.parse(url)
  Capybara.current_session.visit([url.path, url.query].compact.join('?'))
end

#fromArray<String>

Access to email sender(s)

delegates back to instance of Mail::Message

Returns:

  • (Array<String>)


40
41
42
# File 'lib/capybara/email/driver.rb', line 40

def from
  email.from
end

#rawObject

Plain text email contents

Returns:

  • String



77
78
79
80
81
82
83
84
85
86
87
# File 'lib/capybara/email/driver.rb', line 77

def raw
  if email.mime_type =~ /\Amultipart\/(alternative|related|mixed)\Z/
    if email.html_part
      return email.html_part.body.to_s
    elsif email.text_part
      return email.text_part.body.to_s
    end
  end

  return email.body.to_s
end

#sourceObject

String version of email HTML source

Returns:

  • String



66
67
68
69
70
71
72
# File 'lib/capybara/email/driver.rb', line 66

def source
  if email.mime_type == 'text/plain'
    convert_to_html(raw)
  else
    raw
  end
end

#subjectObject

Access to email subject

delegates back to instance of Mail::Message

Returns:

  • String



22
23
24
# File 'lib/capybara/email/driver.rb', line 22

def subject
  email.subject
end

#toArray<String>

Access to email recipient(s)

delegates back to instance of Mail::Message

Returns:

  • (Array<String>)


31
32
33
# File 'lib/capybara/email/driver.rb', line 31

def to
  email.to
end