Class: Capybara::Node::Email
- Inherits:
-
Document
- Object
- Document
- Capybara::Node::Email
- Defined in:
- lib/capybara/node/email.rb
Instance Method Summary collapse
-
#body ⇒ Mail::Message#body
Delegate to the email body.
-
#body_as_simple_node ⇒ Object
Treat the message’s body as a Capybara::Node::Simple so that selectors actually work instead of raising NotImplementedErrors.
-
#header(key) ⇒ Object
Returns the value of the passed in header key.
-
#headers ⇒ String
Returns the header keys as an array of strings.
-
#inspect ⇒ String
Corrects the inspect string.
-
#save_and_open(file_name = nil) ⇒ Object
Save a snapshot of the page and open it in a browser for inspection.
-
#save_page(path = nil) ⇒ Object
Save a snapshot of the page.
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, *args, &block) ⇒ Object (private)
Tries to send to ‘base` first. If an NotImplementedError is hit because some finders/matchers/etc. aren’t implemented, fall back to treating the message body as a Capybara::Node::Simple
67 68 69 70 71 72 73 |
# File 'lib/capybara/node/email.rb', line 67 def method_missing(meth, *args, &block) begin base.send(meth, *args) rescue NotImplementedError body_as_simple_node.send(meth, *args) end end |
Instance Method Details
#body ⇒ Mail::Message#body
Delegate to the email body
6 7 8 |
# File 'lib/capybara/node/email.rb', line 6 def body base.raw end |
#body_as_simple_node ⇒ Object
Treat the message’s body as a Capybara::Node::Simple so that selectors actually work instead of raising NotImplementedErrors
12 13 14 |
# File 'lib/capybara/node/email.rb', line 12 def body_as_simple_node @body_as_simple_node ||= Capybara.string base.raw end |
#header(key) ⇒ Object
Returns the value of the passed in header key.
19 20 21 |
# File 'lib/capybara/node/email.rb', line 19 def header(key) base.email.header[key].value end |
#headers ⇒ String
Returns the header keys as an array of strings.
26 27 28 |
# File 'lib/capybara/node/email.rb', line 26 def headers base.email.header.fields.map(&:name) end |
#inspect ⇒ String
Corrects the inspect string
33 34 35 |
# File 'lib/capybara/node/email.rb', line 33 def inspect "<#{self.class.to_s}>" end |
#save_and_open(file_name = nil) ⇒ Object
Save a snapshot of the page and open it in a browser for inspection
55 56 57 58 59 60 |
# File 'lib/capybara/node/email.rb', line 55 def save_and_open(file_name = nil) require 'launchy' Launchy.open(save_page(file_name)) rescue LoadError warn 'Please install the launchy gem to open page with save_and_open_page' end |
#save_page(path = nil) ⇒ Object
Save a snapshot of the page.
41 42 43 44 45 46 47 48 49 |
# File 'lib/capybara/node/email.rb', line 41 def save_page(path = nil) path ||= "capybara-email-#{Time.new.strftime("%Y%m%d%H%M%S")}#{rand(10**10)}.html" path = File.(path, Capybara.save_path) if Capybara.save_path FileUtils.mkdir_p(File.dirname(path)) File.open(path,'w') { |f| f.write(body) } path end |