Class: Capybara::Node::Email

Inherits:
Document
  • Object
show all
Defined in:
lib/capybara/node/email.rb

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth, *args, &block) ⇒ Object (private)


58
59
60
# File 'lib/capybara/node/email.rb', line 58

def method_missing(meth, *args, &block)
  base.send(meth, *args)
end

Instance Method Details

#bodyMail::Message#body

Delegate to the email body

Returns:

  • (Mail::Message#body)

6
7
8
# File 'lib/capybara/node/email.rb', line 6

def body
  base.raw
end

#header(key) ⇒ Object

Returns the value of the passed in header key.

Returns:

  • String


13
14
15
# File 'lib/capybara/node/email.rb', line 13

def header(key)
  base.email.header[key].value
end

#headersString

Returns the header keys as an array of strings.

Returns:

  • (String)

20
21
22
# File 'lib/capybara/node/email.rb', line 20

def headers
  base.email.header.fields.map(&:name)
end

#inspectString

Corrects the inspect string

Returns:

  • (String)

27
28
29
# File 'lib/capybara/node/email.rb', line 27

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

Parameters:

  • path (String)

    The path to where it should be saved [optional]


49
50
51
52
53
54
# File 'lib/capybara/node/email.rb', line 49

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.

Parameters:

  • path (String) (defaults to: nil)

    The path to where it should be saved [optional]


35
36
37
38
39
40
41
42
43
# File 'lib/capybara/node/email.rb', line 35

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_and_open_page_path) if Capybara.save_and_open_page_path

  FileUtils.mkdir_p(File.dirname(path))

  File.open(path,'w') { |f| f.write(body) }
  path
end