From e1444d58ef768665987bd1717e414c9463e8263f Mon Sep 17 00:00:00 2001 From: gaffo Date: Thu, 13 Nov 2008 22:33:33 -0600 Subject: [PATCH] added support for windows and cygwin --- lib/webrat/core/session.rb | 15 +++++++++++++-- spec/webrat/core/session_spec.rb | 17 ++++++++++++++++- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/lib/webrat/core/session.rb b/lib/webrat/core/session.rb index 2a9f5dd..c1fec8e 100644 --- a/lib/webrat/core/session.rb +++ b/lib/webrat/core/session.rb @@ -152,8 +152,13 @@ module Webrat alias_method :visits, :visit - def open_in_browser(path) #:nodoc - `open #{path}` + 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 def rewrite_css_and_image_references(response_html) #:nodoc @@ -186,5 +191,11 @@ module Webrat def_delegators :current_scope, :should_see def_delegators :current_scope, :should_not_see def_delegators :current_scope, :field_labeled + + private + # accessor for testing + def ruby_platform + RUBY_PLATFORM + end end end diff --git a/spec/webrat/core/session_spec.rb b/spec/webrat/core/session_spec.rb index fc7c9df..f8a1e4d 100644 --- a/spec/webrat/core/session_spec.rb +++ b/spec/webrat/core/session_spec.rb @@ -21,12 +21,27 @@ describe Webrat::Session do session.current_dom.should be_an_instance_of(Nokogiri::HTML::Document) end - it "should open the page in the browser" do + it "should open the page in the browser in MacOSX" do session = Webrat::Session.new + session.should_receive(:ruby_platform).and_return 'darwin' session.should_receive(:`).with("open path") session.open_in_browser("path") end + it "should open the page in the browser in cygwin" do + session = Webrat::Session.new + session.should_receive(:ruby_platform).and_return 'i386-cygwin' + session.should_receive(:`).with("rundll32 url.dll,FileProtocolHandler path\\to\\file") + session.open_in_browser("path/to/file") + end + + it "should open the page in the browser in Win32" do + session = Webrat::Session.new + session.should_receive(:ruby_platform).and_return 'win32' + session.should_receive(:`).with("rundll32 url.dll,FileProtocolHandler path\\to\\file") + session.open_in_browser("path/to/file") + end + it "should provide a current_page for backwards compatibility" do session = Webrat::Session.new current_page = session.current_page