added support for windows and cygwin
This commit is contained in:
parent
82c6be380e
commit
e1444d58ef
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue