Skip to content

Commit

Permalink
Stole for Capybara. Should resolve #15
Browse files Browse the repository at this point in the history
  • Loading branch information
bcardarella committed Jan 4, 2013
1 parent 3bda461 commit 07cc163
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions lib/capybara/node/email.rb
Expand Up @@ -28,9 +28,28 @@ def from
base.from
end

# Will open the email body in your browser
def save_and_open
::Capybara.save_and_open_page(body)
# Save a snapshot of the page.
#
# @param [String] path The path to where it should be saved [optional]
#
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

# 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]
#
def save_and_open_page(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
end

0 comments on commit 07cc163

Please sign in to comment.