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



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

def body
  dom.to_xml
end

#domObject

Nokogiri object for traversing content

Returns:

  • Nokogiri::HTML::Document



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

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

#find(selector) ⇒ Array<Capybara::Driver::Node>

Find elements based on given xpath

Parameters:

  • (xpath string)

Returns:

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


64
65
66
# File 'lib/capybara/email/driver.rb', line 64

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

#follow(url) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/capybara/email/driver.rb', line 8

def follow(url)
  url = URI.parse(url)
  url = case Capybara.current_driver
  when :rack_test
    url.to_s
  else
    Capybara.current_session.driver.send(:url, url.request_uri)
  end

  Capybara.current_session.driver.visit url
end

#fromArray<String>

Access to email sender(s)

delegates back to instance of Mail::Message

Returns:

  • (Array<String>)


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

def from
  email.from
end

#rawObject

Plain text email contents

Returns:

  • String



82
83
84
# File 'lib/capybara/email/driver.rb', line 82

def raw
  email.body.encoded
end

#sourceObject

String version of email HTML source

Returns:

  • String



71
72
73
74
75
76
77
# File 'lib/capybara/email/driver.rb', line 71

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



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

def subject
  email.subject
end

#toArray<String>

Access to email recipient(s)

delegates back to instance of Mail::Message

Returns:

  • (Array<String>)


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

def to
  email.to
end