Skip to content

Commit

Permalink
Merge pull request #132 from copiousfreetime/ensure-2.4-and-greater-s…
Browse files Browse the repository at this point in the history
…upport

Lots of cleanup to bring launchy up to date with modern ruby
  • Loading branch information
copiousfreetime committed Feb 27, 2020
2 parents 28a81e2 + ac4dbc2 commit 88eb402
Show file tree
Hide file tree
Showing 23 changed files with 187 additions and 158 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -8,3 +8,4 @@ pkg/
.DS_Store
*.lock
.gem
.byebug_history
13 changes: 6 additions & 7 deletions .travis.yml
@@ -1,9 +1,8 @@
language: ruby
rvm:
- 1.9.3
- 2.0.0
- 2.1
- 2.2
- jruby-18mode # JRuby in 1.8 mode
- jruby-19mode # JRuby in 1.9 mode
- rbx
- "2.4"
- "2.5"
- "2.6"
- "2.7"
- jruby-9.2.10.0
- truffleruby
7 changes: 4 additions & 3 deletions CONTRIBUTING.md
Expand Up @@ -27,9 +27,9 @@ easiest way to contribute.
* Fork the [repo][].
* Create a new branch for your issue: `git checkout -b issue/my-issue`
* Lovingly craft your contribution:
* `rake develop` to get started, or if you prefer bundler `rake develop:using_bundler && bundle`.
* `rake test` to run tests
* Make sure that `rake test` passes. It's important, I said it twice.
* `rake develop` to get started
* `bundle exec rake test` to run tests
* Make sure that `bundle exec rake test` passes. It's important, I said it twice.
* Add yourself to the contributors section below.
* Submit your [pull request][].

Expand All @@ -50,6 +50,7 @@ easiest way to contribute.
* [Cédric Félizard](https://github.com/infertux)
* [Daniel Farina](https://github.com/fdr)
* [Jack Turnbull](https://github.com/jackturnbull)
* [Jeremy Moritz](https://github.com/jeremymoritz)

[GitHub Account]: https://github.com/signup/free "GitHub Signup"
[GitHub Issues]: https://github.com/copiousfreetime/launchy/issues "Launchy Issues"
Expand Down
2 changes: 1 addition & 1 deletion Gemfile
@@ -1,4 +1,4 @@
# DO NOT EDIT - This file is automatically generated
# Make changes to Manifest.txt and/or Rakefile and regenerate
source "https://rubygems.org/"
source "https://rubygems.org"
gemspec
30 changes: 22 additions & 8 deletions README.md
@@ -1,8 +1,10 @@
# launchy

[![Build Status](https://travis-ci.org/copiousfreetime/launchy.svg?branch=master)](https://travis-ci.org/copiousfreetime/launchy)


* [Homepage](https://github.com/copiousfreetime/launchy)
* [Github Project](https://github.com/copiousfreetime/launchy)
* email jeremy at hinegardner dot org

## DESCRIPTION

Expand All @@ -20,7 +22,8 @@ Currently only launching a browser is supported.

## SYNOPSIS

You can use launchy on the commandline, within the Capybara and Rspec-rails testing environment, or via its API.
You can use launchy on the commandline, within the Capybara and Rspec-rails
testing environment, or via its API.

### Commandline

Expand All @@ -30,11 +33,17 @@ There are additional command line options, use `launchy --help` to see them.

### Using the `BROWSER` environment variable

Launchy has a predefined set of common browsers on each platform that it attempts to use, and of course it is not exhaustive. As a fallbabck you can make use of the somewhat standard `BROWSER` environment variable.
Launchy has a predefined set of common browsers on each platform that it
attempts to use, and of course it is not exhaustive. As a fallbabck you can make
use of the somewhat standard `BROWSER` environment variable.

`BROWSER` works in a similar same way to `PATH`. It is a colon (`:`) separated list of commands to try. You can also put in a `%s` in the command and the URL you are attempting to open will be substituted there.
`BROWSER` works in a similar same way to `PATH`. It is a colon (`:`) separated
list of commands to try. You can also put in a `%s` in the command and the URL
you are attempting to open will be substituted there.

As an example if you set `BROWSER=/usr/local/bin/firefox-bin -new-tab '%s':/usr/local/bin/google-chrome-stable` and you call `Launchy.open("http://www.ruby-lang.org/")` then Launchy will try, in order:
As an example if you set `BROWSER=/usr/local/bin/firefox-bin -new-tab
'%s':/usr/local/bin/google-chrome-stable` and you call
`Launchy.open("http://www.ruby-lang.org/")` then Launchy will try, in order:

* `/usr/local/bin/firefox-bin -new-tab 'http://www.ruby-lang.org'`
* `/usr/local/bin/google-chrome-stable http://www.ruby-lang.org`
Expand All @@ -47,16 +56,21 @@ Additional links on the use of `BROWSER` as an environment variable.

### Capybara Testing

First, install [Capybara](https://github.com/jnicklas/capybara) and [Rspec for Rails](https://github.com/rspec/rspec-rails). Capybara provides the following method:
First, install [Capybara](https://github.com/jnicklas/capybara) and [Rspec for
Rails](https://github.com/rspec/rspec-rails). Capybara provides the following
method:

save_and_open_page

When inserted into your code at the place where you would like to open your program, and when rspec is run, Capybara displays this message:
When inserted into your code at the place where you would like to open your
program, and when rspec is run, Capybara displays this message:

Page saved to /home/code/my_app_name/tmp/capybara/capybara-current-date-and-time.html with save_and_open_page.
Please install the launchy gem to open page automatically.

With Launchy installed, when rspec is run again, it will launch an unstyled instance of the specific page. It can be especially useful when debugging errors in integration tests. For example:
With Launchy installed, when rspec is run again, it will launch an unstyled
instance of the specific page. It can be especially useful when debugging errors
in integration tests. For example:

context "signin" do
it "lets a user sign in" do
Expand Down
14 changes: 4 additions & 10 deletions Rakefile
Expand Up @@ -9,16 +9,10 @@ This.homepage = "http://github.com/copiousfreetime/#{ This.name }"
This.ruby_gemspec do |spec|
spec.add_dependency( 'addressable', '~> 2.3')

spec.add_development_dependency( 'rake' , '~> 10.1')
spec.add_development_dependency( 'minitest' , '~> 5.0' )
spec.add_development_dependency( 'rdoc' , '~> 4.1' )
spec.add_development_dependency( 'simplecov', '~> 0.9' )

spec.licenses = ['ISC']
end

This.java_gemspec( This.ruby_gemspec ) do |spec|
spec.add_dependency( 'spoon', '~> 0.0.1' )
spec.add_development_dependency( 'rake' , '~> 13.0')
spec.add_development_dependency( 'minitest' , '~> 5.14' )
spec.add_development_dependency( 'rdoc' , '~> 6.2' )
spec.add_development_dependency( 'simplecov', '~> 0.18' )

spec.licenses = ['ISC']
end
Expand Down
64 changes: 29 additions & 35 deletions launchy.gemspec
Expand Up @@ -4,47 +4,41 @@
# stub: launchy 2.4.3 ruby lib

Gem::Specification.new do |s|
s.name = "launchy"
s.name = "launchy".freeze
s.version = "2.4.3"

s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.require_paths = ["lib"]
s.authors = ["Jeremy Hinegardner"]
s.date = "2015-02-18"
s.description = "Launchy is helper class for launching cross-platform applications in a fire and forget manner. There are application concepts (browser, email client, etc) that are common across all platforms, and they may be launched differently on each platform. Launchy is here to make a common approach to launching external application from within ruby programs."
s.email = "jeremy@copiousfreetime.org"
s.executables = ["launchy"]
s.extra_rdoc_files = ["CONTRIBUTING.md", "HISTORY.md", "Manifest.txt", "README.md"]
s.files = ["CONTRIBUTING.md", "HISTORY.md", "LICENSE", "Manifest.txt", "README.md", "Rakefile", "bin/launchy", "lib/launchy.rb", "lib/launchy/application.rb", "lib/launchy/applications/browser.rb", "lib/launchy/argv.rb", "lib/launchy/cli.rb", "lib/launchy/deprecated.rb", "lib/launchy/descendant_tracker.rb", "lib/launchy/detect.rb", "lib/launchy/detect/host_os.rb", "lib/launchy/detect/host_os_family.rb", "lib/launchy/detect/nix_desktop_environment.rb", "lib/launchy/detect/ruby_engine.rb", "lib/launchy/detect/runner.rb", "lib/launchy/error.rb", "lib/launchy/os_family.rb", "lib/launchy/version.rb", "spec/application_spec.rb", "spec/applications/browser_spec.rb", "spec/cli_spec.rb", "spec/detect/host_os_family_spec.rb", "spec/detect/host_os_spec.rb", "spec/detect/nix_desktop_environment_spec.rb", "spec/detect/ruby_engine_spec.rb", "spec/detect/runner_spec.rb", "spec/launchy_spec.rb", "spec/mock_application.rb", "spec/spec_helper.rb", "spec/tattle-host-os.yaml", "spec/version_spec.rb", "tasks/default.rake", "tasks/this.rb"]
s.homepage = "http://github.com/copiousfreetime/launchy"
s.licenses = ["ISC"]
s.rdoc_options = ["--main", "README.md", "--markup", "tomdoc"]
s.required_ruby_version = Gem::Requirement.new(">= 1.9.3")
s.rubygems_version = "2.4.6"
s.summary = "Launchy is helper class for launching cross-platform applications in a fire and forget manner."
s.test_files = ["spec/application_spec.rb", "spec/applications/browser_spec.rb", "spec/cli_spec.rb", "spec/detect/host_os_family_spec.rb", "spec/detect/host_os_spec.rb", "spec/detect/nix_desktop_environment_spec.rb", "spec/detect/ruby_engine_spec.rb", "spec/detect/runner_spec.rb", "spec/launchy_spec.rb", "spec/mock_application.rb", "spec/spec_helper.rb", "spec/tattle-host-os.yaml", "spec/version_spec.rb"]
s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
s.require_paths = ["lib".freeze]
s.authors = ["Jeremy Hinegardner".freeze]
s.date = "2020-02-27"
s.description = "Launchy is helper class for launching cross-platform applications in a fire and forget manner. There are application concepts (browser, email client, etc) that are common across all platforms, and they may be launched differently on each platform. Launchy is here to make a common approach to launching external applications from within ruby programs.".freeze
s.email = "jeremy@copiousfreetime.org".freeze
s.executables = ["launchy".freeze]
s.extra_rdoc_files = ["CONTRIBUTING.md".freeze, "HISTORY.md".freeze, "Manifest.txt".freeze, "README.md".freeze]
s.files = ["CONTRIBUTING.md".freeze, "HISTORY.md".freeze, "LICENSE".freeze, "Manifest.txt".freeze, "README.md".freeze, "Rakefile".freeze, "bin/launchy".freeze, "lib/launchy.rb".freeze, "lib/launchy/application.rb".freeze, "lib/launchy/applications/browser.rb".freeze, "lib/launchy/argv.rb".freeze, "lib/launchy/cli.rb".freeze, "lib/launchy/deprecated.rb".freeze, "lib/launchy/descendant_tracker.rb".freeze, "lib/launchy/detect.rb".freeze, "lib/launchy/detect/host_os.rb".freeze, "lib/launchy/detect/host_os_family.rb".freeze, "lib/launchy/detect/nix_desktop_environment.rb".freeze, "lib/launchy/detect/ruby_engine.rb".freeze, "lib/launchy/detect/runner.rb".freeze, "lib/launchy/error.rb".freeze, "lib/launchy/os_family.rb".freeze, "lib/launchy/version.rb".freeze, "spec/application_spec.rb".freeze, "spec/applications/browser_spec.rb".freeze, "spec/cli_spec.rb".freeze, "spec/detect/host_os_family_spec.rb".freeze, "spec/detect/host_os_spec.rb".freeze, "spec/detect/nix_desktop_environment_spec.rb".freeze, "spec/detect/ruby_engine_spec.rb".freeze, "spec/detect/runner_spec.rb".freeze, "spec/launchy_spec.rb".freeze, "spec/mock_application.rb".freeze, "spec/spec_helper.rb".freeze, "spec/tattle-host-os.yaml".freeze, "spec/version_spec.rb".freeze, "tasks/default.rake".freeze, "tasks/this.rb".freeze]
s.homepage = "http://github.com/copiousfreetime/launchy".freeze
s.licenses = ["ISC".freeze]
s.rdoc_options = ["--main".freeze, "README.md".freeze, "--markup".freeze, "tomdoc".freeze]
s.required_ruby_version = Gem::Requirement.new(">= 2.4.0".freeze)
s.rubygems_version = "3.1.2".freeze
s.summary = "Launchy is helper class for launching cross-platform applications in a fire and forget manner.".freeze
s.test_files = ["spec/application_spec.rb".freeze, "spec/applications/browser_spec.rb".freeze, "spec/cli_spec.rb".freeze, "spec/detect/host_os_family_spec.rb".freeze, "spec/detect/host_os_spec.rb".freeze, "spec/detect/nix_desktop_environment_spec.rb".freeze, "spec/detect/ruby_engine_spec.rb".freeze, "spec/detect/runner_spec.rb".freeze, "spec/launchy_spec.rb".freeze, "spec/mock_application.rb".freeze, "spec/spec_helper.rb".freeze, "spec/tattle-host-os.yaml".freeze, "spec/version_spec.rb".freeze]

if s.respond_to? :specification_version then
s.specification_version = 4
end

if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
s.add_runtime_dependency(%q<addressable>, ["~> 2.3"])
s.add_development_dependency(%q<rake>, ["~> 10.1"])
s.add_development_dependency(%q<minitest>, ["~> 5.0"])
s.add_development_dependency(%q<rdoc>, ["~> 4.1"])
s.add_development_dependency(%q<simplecov>, ["~> 0.9"])
else
s.add_dependency(%q<addressable>, ["~> 2.3"])
s.add_dependency(%q<rake>, ["~> 10.1"])
s.add_dependency(%q<minitest>, ["~> 5.0"])
s.add_dependency(%q<rdoc>, ["~> 4.1"])
s.add_dependency(%q<simplecov>, ["~> 0.9"])
end
if s.respond_to? :add_runtime_dependency then
s.add_runtime_dependency(%q<addressable>.freeze, ["~> 2.3"])
s.add_development_dependency(%q<rake>.freeze, ["~> 13.0"])
s.add_development_dependency(%q<minitest>.freeze, ["~> 5.14"])
s.add_development_dependency(%q<rdoc>.freeze, ["~> 6.2"])
s.add_development_dependency(%q<simplecov>.freeze, ["~> 0.18"])
else
s.add_dependency(%q<addressable>, ["~> 2.3"])
s.add_dependency(%q<rake>, ["~> 10.1"])
s.add_dependency(%q<minitest>, ["~> 5.0"])
s.add_dependency(%q<rdoc>, ["~> 4.1"])
s.add_dependency(%q<simplecov>, ["~> 0.9"])
s.add_dependency(%q<addressable>.freeze, ["~> 2.3"])
s.add_dependency(%q<rake>.freeze, ["~> 13.0"])
s.add_dependency(%q<minitest>.freeze, ["~> 5.14"])
s.add_dependency(%q<rdoc>.freeze, ["~> 6.2"])
s.add_dependency(%q<simplecov>.freeze, ["~> 0.18"])
end
end
9 changes: 9 additions & 0 deletions lib/launchy.rb
Expand Up @@ -66,6 +66,7 @@ def reset_global_options
Launchy.host_os = nil
Launchy.ruby_engine = nil
Launchy.dry_run = false
Launchy.path = ENV['PATH']
end

def extract_global_options( options )
Expand Down Expand Up @@ -127,6 +128,14 @@ def log(msg)
$stderr.puts "LAUNCHY_DEBUG: #{msg}" if Launchy.debug?
end

def path
@path
end

def path=(path)
@path = path
end

private
def to_bool( arg )
if arg.is_a? String
Expand Down
2 changes: 1 addition & 1 deletion lib/launchy/application.rb
Expand Up @@ -27,7 +27,7 @@ def handling( uri )
#
# Find the given executable in the available paths
def find_executable( bin, *paths )
paths = ENV['PATH'].split( File::PATH_SEPARATOR ) if paths.empty?
paths = Launchy.path.split( File::PATH_SEPARATOR ) if paths.empty?
paths.each do |path|
file = File.join( path, bin )
if File.executable?( file ) then
Expand Down
4 changes: 2 additions & 2 deletions lib/launchy/detect/nix_desktop_environment.rb
Expand Up @@ -33,11 +33,11 @@ def self.browsers
class Kde < NixDesktopEnvironment
def self.is_current_desktop_environment?
ENV['KDE_FULL_SESSION'] &&
Launchy::Application.find_executable( 'kfmclient' )
Launchy::Application.find_executable( 'kde-open' )
end

def self.browser
::Launchy::Argv.new( %w[ kfmclient openURL ] )
::Launchy::Argv.new( 'kde-open' )
end
end

Expand Down
4 changes: 2 additions & 2 deletions lib/launchy/detect/runner.rb
Expand Up @@ -108,8 +108,8 @@ def wet_run( cmd, *args )

class Jruby < Runner
def wet_run( cmd, *args )
require 'spoon'
Spoon.spawnp( *shell_commands( cmd, *args ) )
child_pid = spawn( *shell_commands( cmd, *args ) )
Process.detach( child_pid )
end
end

Expand Down
14 changes: 7 additions & 7 deletions spec/application_spec.rb
Expand Up @@ -14,30 +14,30 @@ def self.handles?( uri )
uri.scheme == "junk2"
end
end
Launchy::Application.children.must_include( Junk2App )
_(Launchy::Application.children).must_include( Junk2App )
Launchy::Application.children.delete( Junk2App )
end

it "can find an app" do
Launchy::Application.children.must_include( JunkApp )
Launchy::Application.children.size.must_equal 3
_(Launchy::Application.children).must_include( JunkApp )
_(Launchy::Application.children.size).must_equal 3
uri = Addressable::URI.parse( "junk:///foo" )
Launchy::Application.handling( uri ).must_equal( JunkApp )
_(Launchy::Application.handling( uri )).must_equal( JunkApp )
end

it "raises an error if an application cannot be found for the given scheme" do
uri = Addressable::URI.parse( "foo:///bar" )
lambda { Launchy::Application.handling( uri ) }.must_raise( Launchy::ApplicationNotFoundError )
_(lambda { Launchy::Application.handling( uri ) }).must_raise( Launchy::ApplicationNotFoundError )
end

it "can find open or curl or xdg-open" do
found = %w[ open curl xdg-open ].any? do |app|
Launchy::Application.find_executable( app )
end
found.must_equal true
_(found).must_equal true
end

it "does not find xyzzy" do
Launchy::Application.find_executable( "xyzzy" ).must_equal nil
_(Launchy::Application.find_executable( "xyzzy" )).must_be_nil
end
end
48 changes: 29 additions & 19 deletions spec/applications/browser_spec.rb
Expand Up @@ -14,15 +14,22 @@
end

{ 'windows' => 'start "launchy" /b' ,
'darwin' => '/usr/bin/open',
'darwin' => [ '/usr/bin/open', '/bin/open' ], # because running tests on linux
'cygwin' => 'cmd /C start "launchy" /b',

# when running these tests on a linux box, this test will fail
'linux' => nil }.each do |host_os, cmdline|
'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
browser.app_list.first.must_equal cmdline

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

Expand All @@ -32,14 +39,14 @@
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 []
_(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
_(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
Expand All @@ -48,21 +55,24 @@
ENV['BROWSER'] = "do-this-instead"
Launchy.host_os = 'linux'
browser = Launchy::Application::Browser.new
browser.browser_cmdline.must_equal "do-this-instead"
_(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 proble 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/"
# 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
Launchy.open( url )
end
#err.must_match( /wibble/m )
err # something
end
# _, err = capture_subprocess_io do
# begin
# Launchy.open( url )
# rescue => nil
# end
# end
# #_(err).must_match( /wibble/m )
# err # something
#end
end

0 comments on commit 88eb402

Please sign in to comment.