Use Launchy to handle opening pages in the browser with cross-platform compatibility
This commit is contained in:
parent
d60671cd3d
commit
d620e66bd8
|
@ -8,6 +8,7 @@
|
||||||
|
|
||||||
* Minor enhancements
|
* Minor enhancements
|
||||||
|
|
||||||
|
* Use Launchy to handle opening pages in the browser with cross-platform compatibility (Bryan Helmkamp)
|
||||||
* Added support for field_labeled_locators ending in non word characters
|
* Added support for field_labeled_locators ending in non word characters
|
||||||
lh 148 (Zach Dennis)
|
lh 148 (Zach Dennis)
|
||||||
* Filled in tests on click link lh 195 (diabolo)
|
* Filled in tests on click link lh 195 (diabolo)
|
||||||
|
|
|
@ -18,12 +18,10 @@ module Webrat
|
||||||
end
|
end
|
||||||
|
|
||||||
def open_in_browser(path) # :nodoc
|
def open_in_browser(path) # :nodoc
|
||||||
platform = ruby_platform
|
require "launchy"
|
||||||
if platform =~ /cygwin/ || platform =~ /win32/
|
Launchy::Browser.run(path)
|
||||||
`rundll32 url.dll,FileProtocolHandler #{path.gsub("/", "\\\\")}`
|
rescue LoadError
|
||||||
elsif platform =~ /darwin/
|
warn "Sorry, you need to install launchy to open pages: `gem install launchy`"
|
||||||
`open #{path}`
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def rewrite_css_and_image_references(response_html) # :nodoc:
|
def rewrite_css_and_image_references(response_html) # :nodoc:
|
||||||
|
|
|
@ -21,27 +21,6 @@ describe Webrat::Session do
|
||||||
session.should respond_to(:current_dom)
|
session.should respond_to(:current_dom)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should open the page in the browser in MacOSX" do
|
|
||||||
session = Webrat::Session.new
|
|
||||||
session.stub!(:ruby_platform => '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.stub!(:ruby_platform => '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.stub!(:ruby_platform => '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
|
it "should provide a current_page for backwards compatibility" do
|
||||||
session = Webrat::Session.new
|
session = Webrat::Session.new
|
||||||
current_page = session.current_page
|
current_page = session.current_page
|
||||||
|
|
|
@ -17,7 +17,9 @@ describe "save_and_open_page" do
|
||||||
|
|
||||||
File.stub!(:exist? => true)
|
File.stub!(:exist? => true)
|
||||||
Time.stub!(:now => 1234)
|
Time.stub!(:now => 1234)
|
||||||
webrat_session.stub!(:open_in_browser)
|
|
||||||
|
require "launchy"
|
||||||
|
Launchy::Browser.stub!(:run)
|
||||||
|
|
||||||
@file_handle = mock("file handle")
|
@file_handle = mock("file handle")
|
||||||
File.stub!(:open).with(filename, 'w').and_yield(@file_handle)
|
File.stub!(:open).with(filename, 'w').and_yield(@file_handle)
|
||||||
|
@ -48,11 +50,19 @@ describe "save_and_open_page" do
|
||||||
save_and_open_page
|
save_and_open_page
|
||||||
end
|
end
|
||||||
|
|
||||||
it "should open the temp file in a browser" do
|
it "should open the temp file in a browser with Launchy" do
|
||||||
webrat_session.should_receive(:open_in_browser).with(filename)
|
Launchy::Browser.should_receive(:run)
|
||||||
save_and_open_page
|
save_and_open_page
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "should fail gracefully if Launchy is not available" do
|
||||||
|
Launchy::Browser.should_receive(:run).and_raise(LoadError)
|
||||||
|
|
||||||
|
lambda do
|
||||||
|
save_and_open_page
|
||||||
|
end.should_not raise_error
|
||||||
|
end
|
||||||
|
|
||||||
def filename
|
def filename
|
||||||
File.expand_path("./webrat-#{Time.now}.html")
|
File.expand_path("./webrat-#{Time.now}.html")
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue