class Capybara::Node::Email
Public Instance Methods
Delegate to the email body
@return [Mail::Message#body]
# File lib/capybara/node/email.rb, line 6 def body base.raw end
Treat the message's body as a Capybara::Node::Simple so that selectors actually work instead of raising NotImplementedErrors
# File lib/capybara/node/email.rb, line 12 def body_as_simple_node @body_as_simple_node ||= Capybara.string base.raw end
Returns the value of the passed in header key.
@return String
# File lib/capybara/node/email.rb, line 19 def header(key) base.email.header[key].value end
Returns the header keys as an array of strings.
@return [String]
# File lib/capybara/node/email.rb, line 26 def headers base.email.header.fields.map(&:name) end
Corrects the inspect string
@return [String]
# File lib/capybara/node/email.rb, line 33 def inspect "<#{self.class.to_s}>" end
Save a snapshot of the page and open it in a browser for inspection
@param [String] path The path to where it should be saved [optional]
# 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 a snapshot of the page.
@param [String] path The path to where it should be saved [optional]
# 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.expand_path(path, Capybara.save_path) if Capybara.save_path FileUtils.mkdir_p(File.dirname(path)) File.open(path,'w') { |f| f.write(body) } path end
Private Instance Methods
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
# 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