Class: Capybara::Email::Driver
- Inherits:
-
Driver::Base
- Object
- Driver::Base
- Capybara::Email::Driver
- Defined in:
- lib/capybara/email/driver.rb
Instance Attribute Summary collapse
-
#email ⇒ Object
readonly
Returns the value of attribute email.
Instance Method Summary collapse
- #body ⇒ Object
-
#dom ⇒ Object
Nokogiri object for traversing content.
-
#find(selector) ⇒ Array<Capybara::Driver::Node>
(also: #find_xpath)
Find elements based on given xpath.
- #follow(url) ⇒ Object
-
#from ⇒ Array<String>
Access to email sender(s).
-
#initialize(email) ⇒ Driver
constructor
A new instance of Driver.
-
#raw ⇒ Object
Plain text email contents.
-
#source ⇒ Object
String version of email HTML source.
-
#subject ⇒ Object
Access to email subject.
-
#to ⇒ Array<String>
Access to email recipient(s).
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
#email ⇒ Object (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
#body ⇒ Object
13 14 15 |
# File 'lib/capybara/email/driver.rb', line 13 def body dom.to_xml end |
#dom ⇒ Object
Nokogiri object for traversing content
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
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 |
#from ⇒ Array<String>
Access to email sender(s)
delegates back to instance of Mail::Message
40 41 42 |
# File 'lib/capybara/email/driver.rb', line 40 def from email.from end |
#raw ⇒ Object
Plain text email contents
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 |
#source ⇒ Object
String version of email HTML source
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 |
#subject ⇒ Object
Access to email subject
delegates back to instance of Mail::Message
22 23 24 |
# File 'lib/capybara/email/driver.rb', line 22 def subject email.subject end |
#to ⇒ Array<String>
Access to email recipient(s)
delegates back to instance of Mail::Message
31 32 33 |
# File 'lib/capybara/email/driver.rb', line 31 def to email.to end |