launchy 2.0.1 → 2.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +6 -0
- data/HISTORY +6 -0
- data/README +21 -6
- data/Rakefile +8 -3
- data/lib/launchy.rb +4 -9
- data/lib/launchy/application.rb +1 -0
- data/lib/launchy/applications/browser.rb +17 -12
- data/lib/launchy/cli.rb +23 -10
- data/lib/launchy/detect/runner.rb +28 -18
- data/lib/launchy/version.rb +1 -1
- data/spec/applications/browser_spec.rb +39 -0
- data/spec/cli_spec.rb +75 -0
- data/spec/detect/nix_desktop_environment_spec.rb +22 -3
- data/spec/detect/runner_spec.rb +79 -0
- data/spec/launchy_spec.rb +9 -0
- data/spec/spec_helper.rb +1 -1
- data/spec/version_spec.rb +2 -1
- metadata +61 -7
- data/.autotest +0 -28
data/HISTORY
CHANGED
data/README
CHANGED
@@ -20,17 +20,32 @@ Currently only launching a browser is supported.
|
|
20
20
|
|
21
21
|
== SYNOPSIS
|
22
22
|
|
23
|
-
|
23
|
+
You can use launchy on the commandline, or via its API.
|
24
24
|
|
25
|
-
|
25
|
+
=== Commandline
|
26
26
|
|
27
|
-
|
27
|
+
% launchy http://www.ruby-lang.org/
|
28
28
|
|
29
|
-
|
29
|
+
There are additional commandline options, use 'launchy --help' to see them.
|
30
30
|
|
31
|
-
|
31
|
+
=== Public API
|
32
32
|
|
33
|
-
|
33
|
+
In the vein of {Semantic Versioning}[http://semver.org], starting with version 2.0.0, this is the
|
34
|
+
sole supported public API.
|
35
|
+
|
36
|
+
Launchy.open( uri, options = {} )
|
37
|
+
|
38
|
+
At the moment, the only available options are:
|
39
|
+
|
40
|
+
:debug Turn on debugging output
|
41
|
+
:application Explicitly state what application class is going to be used
|
42
|
+
:host_os Explicitly state what host operating system to pretend to be
|
43
|
+
:ruby_engine Explicitly state what ruby engine to pretend to be under
|
44
|
+
:dry_run Do nothing and print the command that would be executed on $stdout
|
45
|
+
|
46
|
+
An example of using the public API:
|
47
|
+
|
48
|
+
Launchy.open( "http://www.ruby-lang.org" )
|
34
49
|
|
35
50
|
== ISC LICENSE
|
36
51
|
|
data/Rakefile
CHANGED
@@ -45,10 +45,15 @@ _
|
|
45
45
|
gem.extras = { :platform => Gem::Platform.new( "java" ) }
|
46
46
|
end
|
47
47
|
|
48
|
-
depend_on "rake"
|
49
|
-
depend_on "minitest", "~> 2.3.1", :development => true
|
50
|
-
depend_on 'bones'
|
48
|
+
depend_on "rake" , "~> 0.9.2", :development => true
|
49
|
+
depend_on "minitest" , "~> 2.3.1", :development => true
|
50
|
+
depend_on 'bones' , "~> 3.7.0", :development => true
|
51
|
+
depend_on 'bones-rcov', "~> 1.0.1", :development => true
|
52
|
+
depend_on 'rcov' , "~> 0.9.9", :development => true
|
53
|
+
depend_on "spoon" , "~> 0.0.1", :development => true
|
51
54
|
|
52
55
|
test.files = FileList["spec/**/*_spec.rb"]
|
53
56
|
test.opts << "-w -Ilib:spec"
|
57
|
+
|
58
|
+
rcov.opts << "--exclude gems"
|
54
59
|
}
|
data/lib/launchy.rb
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
require 'uri'
|
2
2
|
|
3
3
|
#
|
4
|
-
#
|
5
|
-
# call:
|
4
|
+
# The entry point into Launchy. This is the sole supported public API.
|
6
5
|
#
|
7
6
|
# Launchy.open( uri, options = {} )
|
8
7
|
#
|
@@ -12,6 +11,7 @@ require 'uri'
|
|
12
11
|
# :application Explicitly state what application class is going to be used
|
13
12
|
# :host_os Explicitly state what host operating system to pretend to be
|
14
13
|
# :ruby_engine Explicitly state what ruby engine to pretend to be under
|
14
|
+
# :dry_run Do nothing and print the command that would be executed on $stdout
|
15
15
|
#
|
16
16
|
# Other options may be used, and those will be passed directly to the
|
17
17
|
# application class
|
@@ -26,13 +26,8 @@ module Launchy
|
|
26
26
|
begin
|
27
27
|
extract_global_options( options )
|
28
28
|
uri = URI.parse( uri )
|
29
|
-
|
30
|
-
|
31
|
-
else
|
32
|
-
msg = "Unable to launch #{uri} with options #{options.inspect}"
|
33
|
-
Launchy.log "#{self.name} : #{msg}"
|
34
|
-
$stderr.puts msg
|
35
|
-
end
|
29
|
+
app = Launchy::Application.for_scheme( uri )
|
30
|
+
app.new.open( uri, options )
|
36
31
|
rescue Exception => e
|
37
32
|
msg = "Failure in opening #{uri} with options #{options.inspect}: #{e}"
|
38
33
|
Launchy.log "#{self.name} : #{msg}"
|
data/lib/launchy/application.rb
CHANGED
@@ -12,7 +12,7 @@ class Launchy::Application
|
|
12
12
|
end
|
13
13
|
|
14
14
|
def cygwin_app_list
|
15
|
-
[
|
15
|
+
[ 'cmd /C start "Launchy" /d' ]
|
16
16
|
end
|
17
17
|
|
18
18
|
def darwin_app_list
|
@@ -20,7 +20,7 @@ class Launchy::Application
|
|
20
20
|
end
|
21
21
|
|
22
22
|
def nix_app_list
|
23
|
-
nix_de = Launchy::Detect::
|
23
|
+
nix_de = Launchy::Detect::NixDesktopEnvironment.detect
|
24
24
|
app_list = %w[ xdg-open ]
|
25
25
|
app_list << nix_de.browser
|
26
26
|
app_list << nix_de.fallback_browsers
|
@@ -44,25 +44,30 @@ class Launchy::Application
|
|
44
44
|
end
|
45
45
|
|
46
46
|
# Get the full commandline of what we are going to add the uri to
|
47
|
-
def
|
47
|
+
def browser_cmdline
|
48
48
|
possibilities = (browser_env + app_list).flatten
|
49
49
|
possibilities.each do |p|
|
50
50
|
Launchy.log "#{self.class.name} : possibility : #{p}"
|
51
51
|
end
|
52
|
-
|
53
|
-
Launchy.log "#{self.class.name} : Using browser value '#{
|
54
|
-
return
|
52
|
+
browser = possibilities.shift
|
53
|
+
Launchy.log "#{self.class.name} : Using browser value '#{browser}'"
|
54
|
+
return browser
|
55
|
+
end
|
56
|
+
|
57
|
+
def cmd_and_args( uri, options = {} )
|
58
|
+
cmd = browser_cmdline
|
59
|
+
args = [ uri.to_s ]
|
60
|
+
if cmd =~ /%s/ then
|
61
|
+
cmd.gsub!( /%s/, args.shift )
|
62
|
+
end
|
63
|
+
return [cmd, args]
|
55
64
|
end
|
56
65
|
|
57
66
|
# final assembly of the command and do %s substitution
|
58
67
|
# http://www.catb.org/~esr/BROWSER/index.html
|
59
68
|
def open( uri, options = {} )
|
60
|
-
|
61
|
-
|
62
|
-
if b =~ /%s/ then
|
63
|
-
b.gsub!( /%s/, args.shift )
|
64
|
-
end
|
65
|
-
run( b, args )
|
69
|
+
cmd, args = cmd_and_args( uri, options )
|
70
|
+
run( cmd, args )
|
66
71
|
end
|
67
72
|
end
|
68
73
|
end
|
data/lib/launchy/cli.rb
CHANGED
@@ -17,26 +17,26 @@ module Launchy
|
|
17
17
|
|
18
18
|
op.on( "-a", "--application APPLICATION",
|
19
19
|
"Explicitly specify the application class to use in the launch") do |app|
|
20
|
-
options[:application] = app
|
20
|
+
@options[:application] = app
|
21
21
|
end
|
22
22
|
|
23
23
|
op.on( "-d", "--debug",
|
24
24
|
"Force debug. Output lots of information.") do |d|
|
25
|
-
options[:debug] = 'true'
|
25
|
+
@options[:debug] = 'true'
|
26
26
|
end
|
27
27
|
|
28
28
|
op.on( "-e", "--engine RUBY_ENGINE",
|
29
29
|
"Force launchy to behave as if it was on a particular ruby engine.") do |e|
|
30
|
-
options[:ruby_engine] = e
|
30
|
+
@options[:ruby_engine] = e
|
31
31
|
end
|
32
32
|
|
33
33
|
op.on( "-n", "--dry-run", "Don't launchy, print the command to be executed on stdout" ) do |x|
|
34
|
-
options[:dry_run] = true
|
34
|
+
@options[:dry_run] = true
|
35
35
|
end
|
36
36
|
|
37
37
|
op.on( "-o", "--host-os HOST_OS",
|
38
38
|
"Force launchy to behave as if it was on a particular host os.") do |os|
|
39
|
-
options[:host_os] = os
|
39
|
+
@options[:host_os] = os
|
40
40
|
end
|
41
41
|
|
42
42
|
|
@@ -44,27 +44,40 @@ module Launchy
|
|
44
44
|
op.separator "Standard Options:"
|
45
45
|
|
46
46
|
op.on( "-h", "--help", "Print this message.") do |h|
|
47
|
-
puts op.to_s
|
47
|
+
$stdout.puts op.to_s
|
48
48
|
exit 0
|
49
49
|
end
|
50
50
|
|
51
51
|
op.on( "-v", "--version", "Output the version of Launchy") do |v|
|
52
|
-
puts "Launchy version #{Launchy::VERSION}"
|
52
|
+
$stdout.puts "Launchy version #{Launchy::VERSION}"
|
53
53
|
exit 0
|
54
54
|
end
|
55
55
|
|
56
56
|
end
|
57
57
|
end
|
58
58
|
|
59
|
-
def
|
59
|
+
def parse( argv, env )
|
60
60
|
begin
|
61
61
|
parser.parse!( argv )
|
62
|
-
|
62
|
+
return true
|
63
63
|
rescue ::OptionParser::ParseError => pe
|
64
64
|
$stderr.puts "#{parser.program_name}: #{pe}"
|
65
65
|
$stderr.puts "Try `#{parser.program_name} --help for more information."
|
66
|
-
|
66
|
+
return false
|
67
67
|
end
|
68
68
|
end
|
69
|
+
|
70
|
+
def good_run( argv, env )
|
71
|
+
if parse( argv, env ) then
|
72
|
+
Launchy.open( argv.shift, options )
|
73
|
+
return true
|
74
|
+
else
|
75
|
+
return false
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
def run( argv = ARGV, env = ENV )
|
80
|
+
exit 1 unless good_run( argv, env )
|
81
|
+
end
|
69
82
|
end
|
70
83
|
end
|
@@ -8,7 +8,17 @@ module Launchy::Detect
|
|
8
8
|
|
9
9
|
# Detect the current command runner
|
10
10
|
#
|
11
|
+
# This will return an instance of the Runner to be used to do the
|
12
|
+
# application launching.
|
13
|
+
#
|
11
14
|
# If a runner cannot be detected then raise Runner::NotFoundError
|
15
|
+
#
|
16
|
+
# The runner rules are, in order:
|
17
|
+
#
|
18
|
+
# 1) If you are on windows, you use the Windows Runner no matter what
|
19
|
+
# 2) If you are using the jruby engine, use the Jruby Runner. Unless rule
|
20
|
+
# (1) took effect
|
21
|
+
# 3) Use Forkable (barring rules (1) and (2))
|
12
22
|
def self.detect
|
13
23
|
host_os_family = Launchy::Detect::HostOsFamily.detect
|
14
24
|
ruby_engine = Launchy::Detect::RubyEngine.detect
|
@@ -28,8 +38,8 @@ module Launchy::Detect
|
|
28
38
|
#
|
29
39
|
def shell_commands( cmd, args )
|
30
40
|
cmdline = [ cmd.shellsplit ]
|
31
|
-
cmdline << args.collect{ |a| a.to_s.shellescape }
|
32
|
-
return
|
41
|
+
cmdline << args.flatten.collect{ |a| a.to_s.shellescape }
|
42
|
+
return commandline_normalize( cmdline )
|
33
43
|
end
|
34
44
|
|
35
45
|
def commandline_normalize( cmdline )
|
@@ -39,9 +49,13 @@ module Launchy::Detect
|
|
39
49
|
return c
|
40
50
|
end
|
41
51
|
|
52
|
+
def dry_run( cmd, *args )
|
53
|
+
shell_commands(cmd, args).join(" ")
|
54
|
+
end
|
55
|
+
|
42
56
|
def run( cmd, *args )
|
43
57
|
if Launchy.dry_run? then
|
44
|
-
puts dry_run( cmd, *args )
|
58
|
+
$stdout.puts dry_run( cmd, *args )
|
45
59
|
else
|
46
60
|
wet_run( cmd, *args )
|
47
61
|
end
|
@@ -53,40 +67,36 @@ module Launchy::Detect
|
|
53
67
|
#---------------------------------------
|
54
68
|
|
55
69
|
class Windows < Runner
|
70
|
+
|
71
|
+
def all_args( cmd, *args )
|
72
|
+
[ 'cmd', '/c', *shell_commands( cmd, *args ) ]
|
73
|
+
end
|
74
|
+
|
56
75
|
def dry_run( cmd, *args )
|
57
|
-
|
76
|
+
all_args( cmd, *args ).join(" ")
|
58
77
|
end
|
59
78
|
|
60
|
-
def shell_commands( cmd, args )
|
79
|
+
def shell_commands( cmd, *args )
|
61
80
|
cmdline = [ cmd ]
|
62
|
-
cmdline << args.collect { |a| a.to_s.gsub("&", "^&") }
|
81
|
+
cmdline << args.flatten.collect { |a| a.to_s.gsub("&", "^&") }
|
63
82
|
return commandline_normalize( cmdline )
|
64
83
|
end
|
65
84
|
|
66
85
|
def wet_run( cmd, *args )
|
67
|
-
system(
|
86
|
+
system( *all_args( cmd, *args ) )
|
68
87
|
end
|
69
88
|
end
|
70
89
|
|
71
90
|
class Jruby < Runner
|
72
|
-
|
73
|
-
def dry_run( cmd, *args )
|
74
|
-
shell_commands(cmd, args).join(" ")
|
75
|
-
end
|
76
|
-
|
77
91
|
def wet_run( cmd, *args )
|
78
|
-
Spoon.spawnp( *shell_commands( cmd, args ) )
|
92
|
+
Spoon.spawnp( *shell_commands( cmd, *args ) )
|
79
93
|
end
|
80
94
|
end
|
81
95
|
|
82
96
|
class Forkable < Runner
|
83
|
-
def dry_run( cmd, *args )
|
84
|
-
shell_commands(cmd, args).join(" ")
|
85
|
-
end
|
86
|
-
|
87
97
|
def wet_run( cmd, *args )
|
88
98
|
child_pid = fork do
|
89
|
-
exec( *shell_commands( cmd, args ))
|
99
|
+
exec( *shell_commands( cmd, *args ))
|
90
100
|
exit!
|
91
101
|
end
|
92
102
|
Process.detach( child_pid )
|
data/lib/launchy/version.rb
CHANGED
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Launchy::Application::Browser do
|
4
|
+
before do
|
5
|
+
Launchy.reset_global_options
|
6
|
+
ENV['KDE_FULL_SESSION'] = "launchy"
|
7
|
+
@test_url = "http://example.com/"
|
8
|
+
end
|
9
|
+
|
10
|
+
after do
|
11
|
+
Launchy.reset_global_options
|
12
|
+
ENV.delete( 'KDE_FULL_SESSION' )
|
13
|
+
end
|
14
|
+
|
15
|
+
{ 'windows' => 'start "Launchy" /d' ,
|
16
|
+
'darwin' => '/usr/bin/open',
|
17
|
+
'cygwin' => 'cmd /C start "Launchy" /d',
|
18
|
+
|
19
|
+
# when running these tests on a linux box, this test will fail
|
20
|
+
'linux' => nil }.each do |host_os, cmdline|
|
21
|
+
it "when host_os is '#{host_os}' the appropriate 'app_list' method is called" do
|
22
|
+
Launchy.host_os = host_os
|
23
|
+
browser = Launchy::Application::Browser.new
|
24
|
+
browser.app_list.first.must_equal cmdline
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
%w[ linux windows darwin cygwin ].each do |host_os|
|
29
|
+
it "the BROWSER environment variable overrides any host defaults on '#{host_os}'" do
|
30
|
+
ENV['BROWSER'] = "my_special_browser --new-tab '%s'"
|
31
|
+
Launchy.host_os = host_os
|
32
|
+
browser = Launchy::Application::Browser.new
|
33
|
+
cmd, args = browser.cmd_and_args( @test_url )
|
34
|
+
cmd.must_equal "my_special_browser --new-tab 'http://example.com/'"
|
35
|
+
args.must_equal []
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
data/spec/cli_spec.rb
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Launchy::Cli do
|
4
|
+
|
5
|
+
before do
|
6
|
+
@old_stderr = $stderr
|
7
|
+
$stderr = StringIO.new
|
8
|
+
|
9
|
+
@old_stdout = $stdout
|
10
|
+
$stdout = StringIO.new
|
11
|
+
Launchy.reset_global_options
|
12
|
+
end
|
13
|
+
|
14
|
+
after do
|
15
|
+
Launchy.reset_global_options
|
16
|
+
$stderr = @old_stderr
|
17
|
+
$stdout = @old_stdout
|
18
|
+
end
|
19
|
+
|
20
|
+
def cli_test( argv, env, exit_val, stderr_regex, stdout_regex )
|
21
|
+
begin
|
22
|
+
Launchy::Cli.new.run( argv, env )
|
23
|
+
rescue SystemExit => se
|
24
|
+
se.status.must_equal exit_val
|
25
|
+
$stderr.string.must_match stderr_regex if stderr_regex
|
26
|
+
$stdout.string.must_match stdout_regex if stdout_regex
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
it "exits 1 when invalid options are given" do
|
31
|
+
cli_test( %w[ -z foo ], {}, 1, /invalid option/, nil )
|
32
|
+
end
|
33
|
+
|
34
|
+
%w[ -h --help ].each do |opt|
|
35
|
+
it "output help and exits 0 when using #{opt}" do
|
36
|
+
cli_test( [ opt ], {}, 0, nil, /Print this message/m )
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
%w[ -v --version ].each do |opt|
|
41
|
+
it "outputs version and exits 0 when using #{opt}" do
|
42
|
+
cli_test( [ opt ], {}, 0, nil, /Launchy version/ )
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
it "leaves the url on argv after parsing" do
|
47
|
+
l = Launchy::Cli.new
|
48
|
+
argv = %w[ --debug --dry-run http://github.com/copiousfreetime/launchy ]
|
49
|
+
l.parse( argv , {} )
|
50
|
+
argv.size.must_equal 1
|
51
|
+
argv[0].must_equal "http://github.com/copiousfreetime/launchy"
|
52
|
+
end
|
53
|
+
|
54
|
+
it "prints the command on stdout when using --dry-run" do
|
55
|
+
argv = %w[ --debug --dry-run http://github.com/copiousfreetime/launchy ]
|
56
|
+
rc = Launchy::Cli.new.good_run( argv, {} )
|
57
|
+
$stdout.string.must_match %r[github.com]
|
58
|
+
end
|
59
|
+
|
60
|
+
{
|
61
|
+
'--application' => [ :application, 'Browser'],
|
62
|
+
'--engine' => [ :ruby_engine, 'rbx'],
|
63
|
+
'--host-os' => [ :host_os, 'cygwin'] }.each_pair do |opt, val|
|
64
|
+
it "the commandline option #{opt} sets the program option #{val[0]}" do
|
65
|
+
argv = [ opt, val[1], "http://github.com/copiousfreetime/launchy" ]
|
66
|
+
l = Launchy::Cli.new
|
67
|
+
rc = l.parse( argv, {} )
|
68
|
+
rc.must_equal true
|
69
|
+
argv.size.must_equal 1
|
70
|
+
argv[0].must_equal "http://github.com/copiousfreetime/launchy"
|
71
|
+
l.options[val[0]].must_equal val[1]
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
@@ -2,12 +2,31 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Launchy::Detect::NixDesktopEnvironment do
|
4
4
|
|
5
|
-
|
6
|
-
|
5
|
+
before do
|
6
|
+
Launchy.reset_global_options
|
7
|
+
end
|
8
|
+
|
9
|
+
after do
|
10
|
+
Launchy.reset_global_options
|
11
|
+
end
|
12
|
+
|
13
|
+
|
14
|
+
{ "KDE_FULL_SESSION" => Launchy::Detect::NixDesktopEnvironment::Kde,
|
15
|
+
"GNOME_DESKTOP_SESSION_ID" => Launchy::Detect::NixDesktopEnvironment::Gnome }.each_pair do |k,v|
|
7
16
|
it "can detect the desktop environment of a *nix machine using ENV[#{k}]" do
|
8
17
|
ENV[k] = "launchy-test"
|
9
|
-
Launchy::Detect::NixDesktopEnvironment.detect
|
18
|
+
nix_env = Launchy::Detect::NixDesktopEnvironment.detect
|
19
|
+
nix_env.must_equal( v )
|
20
|
+
nix_env.browser.must_equal( v.browser )
|
10
21
|
ENV.delete( k )
|
11
22
|
end
|
23
|
+
end
|
24
|
+
|
25
|
+
|
26
|
+
it "raises an error if it cannot determine the *nix desktop environment" do
|
27
|
+
Launchy.host_os = "linux"
|
28
|
+
ENV.delete( "KDE_FULL_SESSION" )
|
29
|
+
ENV.delete( "GNOME_DESKTOP_SESSION_ID" )
|
30
|
+
lambda { Launchy::Detect::NixDesktopEnvironment.detect }.must_raise Launchy::Detect::NixDesktopEnvironment::NotFoundError
|
12
31
|
end
|
13
32
|
end
|
@@ -0,0 +1,79 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Launchy::Detect::Runner do
|
4
|
+
before do
|
5
|
+
Launchy.reset_global_options
|
6
|
+
@test_url = "http://example.com/?foo=bar&baz=wibble"
|
7
|
+
end
|
8
|
+
|
9
|
+
after do
|
10
|
+
Launchy.reset_global_options
|
11
|
+
end
|
12
|
+
|
13
|
+
it "raises an error when there is an unknown host os" do
|
14
|
+
Launchy.host_os = "foo"
|
15
|
+
lambda{ Launchy::Detect::Runner.detect }.must_raise Launchy::Detect::HostOsFamily::NotFoundError
|
16
|
+
end
|
17
|
+
|
18
|
+
it "raises an error when there is an unknown ruby engine" do
|
19
|
+
Launchy.ruby_engine = "wibble"
|
20
|
+
lambda{ Launchy::Detect::Runner.detect }.must_raise Launchy::Detect::RubyEngine::NotFoundError
|
21
|
+
end
|
22
|
+
|
23
|
+
# On anything that has fork, use Forkable
|
24
|
+
%w[ linux darwin cygwin ].each do |host_os|
|
25
|
+
%w[ ruby rbx macruby ].each do |engine_name|
|
26
|
+
it "engine '#{engine_name}' on OS '#{host_os}' uses runner Forkable" do
|
27
|
+
Launchy.host_os = host_os
|
28
|
+
Launchy.ruby_engine = engine_name
|
29
|
+
engine = Launchy::Detect::Runner.detect
|
30
|
+
engine.must_be_instance_of Launchy::Detect::Runner::Forkable
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
|
36
|
+
# Jruby always uses the Jruby runner except on Windows
|
37
|
+
{ 'mingw' => Launchy::Detect::Runner::Windows,
|
38
|
+
'linux' => Launchy::Detect::Runner::Jruby,
|
39
|
+
'darwin' => Launchy::Detect::Runner::Jruby,
|
40
|
+
'cygwin' => Launchy::Detect::Runner::Jruby, }.each_pair do |host_os, runner|
|
41
|
+
it "engine 'jruby' on OS '#{host_os}' uses runner #{runner.name}" do
|
42
|
+
Launchy.host_os = host_os
|
43
|
+
Launchy.ruby_engine = 'jruby'
|
44
|
+
engine = Launchy::Detect::Runner.detect
|
45
|
+
engine.must_be_instance_of runner
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
# If you are on windows, no matter what engine, you use the windows runner
|
50
|
+
%w[ ruby rbx jruby macruby ].each do |engine_name|
|
51
|
+
it "uses a Windows runner when the engine is '#{engine_name}'" do
|
52
|
+
Launchy.host_os = "mingw"
|
53
|
+
Launchy.ruby_engine = engine_name
|
54
|
+
e = Launchy::Detect::Runner.detect
|
55
|
+
e.must_be_instance_of Launchy::Detect::Runner::Windows
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
it "Windows launches use the 'cmd' command" do
|
60
|
+
win = Launchy::Detect::Runner::Windows.new
|
61
|
+
cmd = win.dry_run( "not-really", [ "http://example.com" ] )
|
62
|
+
cmd.must_equal 'cmd /c not-really http://example.com'
|
63
|
+
end
|
64
|
+
|
65
|
+
it "Windows escapes '&' in urls" do
|
66
|
+
win = Launchy::Detect::Runner::Windows.new
|
67
|
+
win.all_args( "not-really", [ @test_url ] ).must_equal [ 'cmd', '/c', 'not-really', 'http://example.com/?foo=bar^&baz=wibble' ]
|
68
|
+
|
69
|
+
cmd = win.dry_run( "not-really", [ @test_url ] )
|
70
|
+
cmd.must_equal 'cmd /c not-really http://example.com/?foo=bar^&baz=wibble'
|
71
|
+
end
|
72
|
+
|
73
|
+
it "Jruby escapes '&' in urls" do
|
74
|
+
jruby = Launchy::Detect::Runner::Jruby.new
|
75
|
+
cmd = jruby.dry_run( "not-really", [ @test_url ])
|
76
|
+
cmd.must_equal 'not-really http://example.com/\\?foo\\=bar\\&baz\\=wibble'
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
data/spec/launchy_spec.rb
CHANGED
@@ -4,10 +4,13 @@ describe Launchy do
|
|
4
4
|
|
5
5
|
before do
|
6
6
|
Launchy.reset_global_options
|
7
|
+
@stderr = $stderr
|
8
|
+
$stderr = StringIO.new
|
7
9
|
end
|
8
10
|
|
9
11
|
after do
|
10
12
|
Launchy.reset_global_options
|
13
|
+
$stderr = @stderr
|
11
14
|
end
|
12
15
|
|
13
16
|
it "logs to stderr when LAUNCHY_DEBUG environment variable is set" do
|
@@ -39,4 +42,10 @@ describe Launchy do
|
|
39
42
|
Launchy.extract_global_options( { :ruby_engine => "myruby" } )
|
40
43
|
Launchy.ruby_engine.must_equal 'myruby'
|
41
44
|
end
|
45
|
+
|
46
|
+
it "prints an error on stderr when no scheme is found for the given uri" do
|
47
|
+
Launchy.open( "blah://something/invalid" )
|
48
|
+
$stderr.string.must_match( /Failure in opening/ )
|
49
|
+
end
|
50
|
+
|
42
51
|
end
|
data/spec/spec_helper.rb
CHANGED
data/spec/version_spec.rb
CHANGED
@@ -2,7 +2,8 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe 'Launchy::VERSION' do
|
4
4
|
it "should have a #.#.# format" do
|
5
|
-
Launchy::VERSION.must_match /\d+\.\d+\.\d+/
|
5
|
+
Launchy::VERSION.must_match( /\d+\.\d+\.\d+/ )
|
6
|
+
Launchy::Version.to_s.must_match( /\d+\.\d+\.\d+/ )
|
6
7
|
Launchy::Version.to_a.each do |n|
|
7
8
|
n.to_i.must_be :>=, 0
|
8
9
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: launchy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 11
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 2
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 2.0.
|
9
|
+
- 2
|
10
|
+
version: 2.0.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Jeremy Hinegardner
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-07-
|
18
|
+
date: 2011-07-17 00:00:00 -06:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -67,9 +67,57 @@ dependencies:
|
|
67
67
|
type: :development
|
68
68
|
version_requirements: *id003
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
|
-
name: bones
|
70
|
+
name: bones-rcov
|
71
71
|
prerelease: false
|
72
72
|
requirement: &id004 !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ~>
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
hash: 21
|
78
|
+
segments:
|
79
|
+
- 1
|
80
|
+
- 0
|
81
|
+
- 1
|
82
|
+
version: 1.0.1
|
83
|
+
type: :development
|
84
|
+
version_requirements: *id004
|
85
|
+
- !ruby/object:Gem::Dependency
|
86
|
+
name: rcov
|
87
|
+
prerelease: false
|
88
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ~>
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
hash: 41
|
94
|
+
segments:
|
95
|
+
- 0
|
96
|
+
- 9
|
97
|
+
- 9
|
98
|
+
version: 0.9.9
|
99
|
+
type: :development
|
100
|
+
version_requirements: *id005
|
101
|
+
- !ruby/object:Gem::Dependency
|
102
|
+
name: spoon
|
103
|
+
prerelease: false
|
104
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ~>
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
hash: 29
|
110
|
+
segments:
|
111
|
+
- 0
|
112
|
+
- 0
|
113
|
+
- 1
|
114
|
+
version: 0.0.1
|
115
|
+
type: :development
|
116
|
+
version_requirements: *id006
|
117
|
+
- !ruby/object:Gem::Dependency
|
118
|
+
name: bones
|
119
|
+
prerelease: false
|
120
|
+
requirement: &id007 !ruby/object:Gem::Requirement
|
73
121
|
none: false
|
74
122
|
requirements:
|
75
123
|
- - ">="
|
@@ -81,7 +129,7 @@ dependencies:
|
|
81
129
|
- 0
|
82
130
|
version: 3.7.0
|
83
131
|
type: :development
|
84
|
-
version_requirements: *
|
132
|
+
version_requirements: *id007
|
85
133
|
description: |
|
86
134
|
Launchy is helper class for launching cross-platform applications in a
|
87
135
|
fire and forget manner.
|
@@ -102,7 +150,7 @@ extra_rdoc_files:
|
|
102
150
|
- README
|
103
151
|
- bin/launchy
|
104
152
|
files:
|
105
|
-
- .
|
153
|
+
- .gitignore
|
106
154
|
- HISTORY
|
107
155
|
- LICENSE
|
108
156
|
- NOTES
|
@@ -124,10 +172,13 @@ files:
|
|
124
172
|
- lib/launchy/os_family.rb
|
125
173
|
- lib/launchy/version.rb
|
126
174
|
- spec/application_spec.rb
|
175
|
+
- spec/applications/browser_spec.rb
|
176
|
+
- spec/cli_spec.rb
|
127
177
|
- spec/detect/host_os_family_spec.rb
|
128
178
|
- spec/detect/host_os_spec.rb
|
129
179
|
- spec/detect/nix_desktop_environment_spec.rb
|
130
180
|
- spec/detect/ruby_engine_spec.rb
|
181
|
+
- spec/detect/runner_spec.rb
|
131
182
|
- spec/launchy_spec.rb
|
132
183
|
- spec/mock_scheme.rb
|
133
184
|
- spec/spec_helper.rb
|
@@ -170,9 +221,12 @@ specification_version: 3
|
|
170
221
|
summary: Launchy is helper class for launching cross-platform applications in a fire and forget manner.
|
171
222
|
test_files:
|
172
223
|
- spec/application_spec.rb
|
224
|
+
- spec/applications/browser_spec.rb
|
225
|
+
- spec/cli_spec.rb
|
173
226
|
- spec/detect/host_os_family_spec.rb
|
174
227
|
- spec/detect/host_os_spec.rb
|
175
228
|
- spec/detect/nix_desktop_environment_spec.rb
|
176
229
|
- spec/detect/ruby_engine_spec.rb
|
230
|
+
- spec/detect/runner_spec.rb
|
177
231
|
- spec/launchy_spec.rb
|
178
232
|
- spec/version_spec.rb
|
data/.autotest
DELETED
@@ -1,28 +0,0 @@
|
|
1
|
-
# vim: ft=ruby
|
2
|
-
|
3
|
-
require 'autotest/growl'
|
4
|
-
|
5
|
-
Autotest.add_hook :initialize do |at|
|
6
|
-
|
7
|
-
at.libs = "lib:spec"
|
8
|
-
at.testlib = 'minitest/autorun'
|
9
|
-
|
10
|
-
at.add_exception 'coverage.info'
|
11
|
-
at.add_exception 'coverage'
|
12
|
-
at.add_exception '.git'
|
13
|
-
|
14
|
-
at.clear_mappings
|
15
|
-
|
16
|
-
at.add_mapping(%r|^spec/.*_spec\.rb$|) do |filename, _|
|
17
|
-
filename
|
18
|
-
end
|
19
|
-
|
20
|
-
at.add_mapping(%r|^lib/(.*)\.rb$|) do |_, match|
|
21
|
-
[ "test/#{match[1]}_spec.rb" ]
|
22
|
-
end
|
23
|
-
|
24
|
-
at.add_mapping(%r|^spec/spec_helper\.rb|) do
|
25
|
-
at.files_matching( %r|^spec/.*_spec\.rb| )
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|