Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge commit 'gaffo/multi_os_for_open_in_browser'
  • Loading branch information
brynary committed Nov 14, 2008
2 parents 74dce87 + e1444d5 commit 1cdf958
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
15 changes: 13 additions & 2 deletions lib/webrat/core/session.rb
Expand Up @@ -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
Expand Down Expand Up @@ -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
17 changes: 16 additions & 1 deletion spec/webrat/core/session_spec.rb
Expand Up @@ -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
Expand Down

0 comments on commit 1cdf958

Please sign in to comment.