diff --git a/lib/webrat/core/session.rb b/lib/webrat/core/session.rb index 2a9f5dd8..c1fec8ef 100644 --- a/lib/webrat/core/session.rb +++ b/lib/webrat/core/session.rb @@ -152,8 +152,13 @@ def visit(url = nil, http_method = :get, data = {}) 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 @@ def page_scope #:nodoc: 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 25b2b903..a30a3c22 100644 --- a/spec/webrat/core/session_spec.rb +++ b/spec/webrat/core/session_spec.rb @@ -21,12 +21,27 @@ def session.response_body session.current_dom.should respond_to(:search) 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