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



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

def body
  dom.to_xml
end

#domObject

Nokogiri object for traversing content

Returns:

  • Nokogiri::HTML::Document



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

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>)


66
67
68
# File 'lib/capybara/email/driver.rb', line 66

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
19
20
# 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
  when :poltergeist
    Capybara.current_session.driver.app_server.url(url.request_uri)
  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>)


50
51
52
# File 'lib/capybara/email/driver.rb', line 50

def from
  email.from
end

#rawObject

Plain text email contents

Returns:

  • String



84
85
86
# File 'lib/capybara/email/driver.rb', line 84

def raw
  email.body.encoded
end

#sourceObject

String version of email HTML source

Returns:

  • String



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

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



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

def subject
  email.subject
end

#toArray<String>

Access to email recipient(s)

delegates back to instance of Mail::Message

Returns:

  • (Array<String>)


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

def to
  email.to
end