1
0
Fork 0
mirror of https://github.com/teamcapybara/capybara.git synced 2022-11-09 12:08:07 -05:00

Move implementation of save and open page into session

This commit is contained in:
Jonas Nicklas 2012-07-24 09:05:50 +02:00
parent 1df6aa3d5c
commit 6e13047dd3
2 changed files with 21 additions and 27 deletions

View file

@ -292,16 +292,31 @@ module Capybara
##
#
# Save a snapshot of the page and open it in a browser for inspection
# Save a snapshot of the page.
#
def save_page(file_name=nil)
require 'capybara/util/save_and_open_page'
Capybara.save_page(body, file_name)
# @param [String] path The path to where it should be saved [optional]
#
def save_page(path=nil)
path ||= "capybara-#{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 'capybara/util/save_and_open_page'
Capybara.save_and_open_page(body, file_name)
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
##

View file

@ -1,21 +0,0 @@
module Capybara
class << self
def save_page(html, path=nil)
path ||= "capybara-#{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(html) }
path
end
def save_and_open_page(html, file_name=nil)
require "launchy"
path = save_page(html, file_name)
Launchy.open(path)
rescue LoadError
warn "Please install the launchy gem to open page with save_and_open_page"
end
end
end