Merge commit 'gaffo/multi_os_for_open_in_browser'

This commit is contained in:
Bryan Helmkamp 2008-11-13 23:53:36 -05:00
commit 1cdf95851b
2 changed files with 29 additions and 3 deletions

View File

@ -152,9 +152,14 @@ module Webrat
alias_method :visits, :visit
def open_in_browser(path) #:nodoc
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
return response_html unless doc_root
@ -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

View File

@ -21,12 +21,27 @@ describe Webrat::Session do
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