1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78
|
require 'spec_helper'
describe Launchy::Application::Browser do
before do
Launchy.reset_global_options
ENV['KDE_FULL_SESSION'] = "launchy"
@test_url = "http://example.com/"
end
after do
Launchy.reset_global_options
ENV.delete( 'KDE_FULL_SESSION' )
ENV.delete( 'BROWSER' )
end
{ 'windows' => 'start "launchy" /b' ,
#'darwin' => [ '/usr/bin/open', '/bin/open' ], # because running tests on linux
'cygwin' => 'cmd /C start "launchy" /b',
'linux' => [nil, "xdg-open"], # because running tests on linux
}.each do |host_os, expected|
it "when host_os is '#{host_os}' the appropriate 'app_list' method is called" do
Launchy.host_os = host_os
browser = Launchy::Application::Browser.new
item = browser.app_list.first
item = item.to_s if item.kind_of?(::Launchy::Argv)
case expected
when Array
_(expected).must_include item
when String
_(item).must_equal expected
end
end
end
%w[ linux windows darwin cygwin ].each do |host_os|
it "the BROWSER environment variable overrides any host defaults on '#{host_os}'" do
ENV['BROWSER'] = "my_special_browser --new-tab '%s'"
Launchy.host_os = host_os
browser = Launchy::Application::Browser.new
cmd, args = browser.cmd_and_args( @test_url )
_(cmd).must_equal "my_special_browser --new-tab 'http://example.com/'"
_(args).must_equal []
end
end
it "handles a file on the file system when there is no file:// scheme" do
uri = Addressable::URI.parse( __FILE__ )
_(Launchy::Application::Browser.handles?( uri )).must_equal true
end
it "handles the case where $BROWSER is set and no *nix desktop environment is found" do
ENV.delete( "KDE_FULL_SESSION" )
ENV.delete( "GNOME_DESKTOP_SESSION_ID" )
ENV['BROWSER'] = "do-this-instead"
Launchy.host_os = 'linux'
browser = Launchy::Application::Browser.new
_(browser.browser_cmdline).must_equal "do-this-instead"
end
# NOTE: Unable to figure out how capture the stderr from the child which has
# moved it at least once. This test just serves the purpose of noting why
# something happens, and the problem we are attempting to fix.
#it "When BROWSER is set to something that is not executable, error still appears on stderr" do
# ENV['BROWSER'] = "not-an-app"
# url = "http://example.com/"
# _, err = capture_subprocess_io do
# begin
# Launchy.open( url )
# rescue => nil
# end
# end
# #_(err).must_match( /wibble/m )
# err # something
#end
end
|