Sha256: 0526c480bc013d136f60198dcc98228d4993deed44fa137d4ecf40fe97f4ce26
Contents?: true
Size: 1008 Bytes
Versions: 10
Compression:
Stored size: 1008 Bytes
Contents
module Capybara module SaveAndOpenPage extend(self) def save_and_open_page(html) name="capybara-#{Time.new.strftime("%Y%m%d%H%M%S")}.html" FileUtils.touch(name) unless File.exist?(name) tempfile = File.new(name,'w') tempfile.write(rewrite_css_and_image_references(html)) tempfile.close open_in_browser(tempfile.path) end def open_in_browser(path) # :nodoc require "launchy" Launchy::Browser.run(path) rescue LoadError warn "Sorry, you need to install launchy to open pages: `gem install launchy`" end def rewrite_css_and_image_references(response_html) # :nodoc: return response_html unless Capybara.asset_root directories = Dir.new(Capybara.asset_root).entries.inject([]) do |list, name| list << name if File.directory?(name) and not name.to_s =~ /^\./ list end response_html.gsub(/("|')\/(#{directories.join('|')})/, '\1' + Capybara.asset_root.to_s + '/\2') end end end
Version data entries
10 entries across 10 versions & 6 rubygems