Module: Webrat::SaveAndOpenPage
- Included in:
- SeleniumSession, Session
- Defined in:
- lib/webrat/core/save_and_open_page.rb
Instance Method Summary collapse
-
#doc_root ⇒ Object
:nodoc:.
-
#open_in_browser(path) ⇒ Object
:nodoc.
-
#rewrite_css_and_image_references(response_html) ⇒ Object
:nodoc:.
-
#save_and_open_page ⇒ Object
Saves the page out to RAILS_ROOT/tmp/ and opens it in the default web browser if on OS X.
-
#saved_page_dir ⇒ Object
:nodoc:.
Instance Method Details
#doc_root ⇒ Object
:nodoc:
38 39 40 |
# File 'lib/webrat/core/save_and_open_page.rb', line 38 def doc_root #:nodoc: nil end |
#open_in_browser(path) ⇒ Object
:nodoc
20 21 22 23 24 25 26 27 |
# File 'lib/webrat/core/save_and_open_page.rb', line 20 def open_in_browser(path) # :nodoc platform = ruby_platform if platform =~ /cygwin/ || platform =~ /win32/ `rundll32 url.dll,FileProtocolHandler #{path.gsub("/", "\\\\")}` elsif platform =~ /darwin/ `open #{path}` end end |
#rewrite_css_and_image_references(response_html) ⇒ Object
:nodoc:
29 30 31 32 |
# File 'lib/webrat/core/save_and_open_page.rb', line 29 def rewrite_css_and_image_references(response_html) # :nodoc: return response_html unless doc_root response_html.gsub(/"\/(stylesheets|images)/, doc_root + '/\1') end |
#save_and_open_page ⇒ Object
Saves the page out to RAILS_ROOT/tmp/ and opens it in the default web browser if on OS X. Useful for debugging.
Example:
save_and_open_page
8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/webrat/core/save_and_open_page.rb', line 8 def save_and_open_page return unless File.exist?(saved_page_dir) filename = "#{saved_page_dir}/webrat-#{Time.now.to_i}.html" File.open(filename, "w") do |f| f.write rewrite_css_and_image_references(response_body) end open_in_browser(filename) end |
#saved_page_dir ⇒ Object
:nodoc:
34 35 36 |
# File 'lib/webrat/core/save_and_open_page.rb', line 34 def saved_page_dir #:nodoc: File.(".") end |