diff --git a/.gitignore b/.gitignore index 2ac0902..b563f6a 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,4 @@ pkg/ .DS_Store *.lock .gem +.byebug_history diff --git a/.travis.yml b/.travis.yml index 27032e9..03195b0 100644 --- a/.travis.yml +++ b/.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 diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index aeab024..49a3c41 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -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][]. @@ -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" diff --git a/Gemfile b/Gemfile index 054ed89..dc4515d 100644 --- a/Gemfile +++ b/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 diff --git a/README.md b/README.md index 07464b8..cc76d42 100644 --- a/README.md +++ b/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 @@ -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 @@ -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` @@ -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 diff --git a/Rakefile b/Rakefile index 56eb181..d03da38 100644 --- a/Rakefile +++ b/Rakefile @@ -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 diff --git a/launchy.gemspec b/launchy.gemspec index 88d179e..77c3af8 100644 --- a/launchy.gemspec +++ b/launchy.gemspec @@ -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, ["~> 2.3"]) - s.add_development_dependency(%q, ["~> 10.1"]) - s.add_development_dependency(%q, ["~> 5.0"]) - s.add_development_dependency(%q, ["~> 4.1"]) - s.add_development_dependency(%q, ["~> 0.9"]) - else - s.add_dependency(%q, ["~> 2.3"]) - s.add_dependency(%q, ["~> 10.1"]) - s.add_dependency(%q, ["~> 5.0"]) - s.add_dependency(%q, ["~> 4.1"]) - s.add_dependency(%q, ["~> 0.9"]) - end + if s.respond_to? :add_runtime_dependency then + s.add_runtime_dependency(%q.freeze, ["~> 2.3"]) + s.add_development_dependency(%q.freeze, ["~> 13.0"]) + s.add_development_dependency(%q.freeze, ["~> 5.14"]) + s.add_development_dependency(%q.freeze, ["~> 6.2"]) + s.add_development_dependency(%q.freeze, ["~> 0.18"]) else - s.add_dependency(%q, ["~> 2.3"]) - s.add_dependency(%q, ["~> 10.1"]) - s.add_dependency(%q, ["~> 5.0"]) - s.add_dependency(%q, ["~> 4.1"]) - s.add_dependency(%q, ["~> 0.9"]) + s.add_dependency(%q.freeze, ["~> 2.3"]) + s.add_dependency(%q.freeze, ["~> 13.0"]) + s.add_dependency(%q.freeze, ["~> 5.14"]) + s.add_dependency(%q.freeze, ["~> 6.2"]) + s.add_dependency(%q.freeze, ["~> 0.18"]) end end diff --git a/lib/launchy.rb b/lib/launchy.rb index f72e7f1..aa6d0e2 100644 --- a/lib/launchy.rb +++ b/lib/launchy.rb @@ -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 ) @@ -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 diff --git a/lib/launchy/application.rb b/lib/launchy/application.rb index 4986531..905808c 100644 --- a/lib/launchy/application.rb +++ b/lib/launchy/application.rb @@ -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 diff --git a/lib/launchy/detect/nix_desktop_environment.rb b/lib/launchy/detect/nix_desktop_environment.rb index f4b91a7..7269c72 100644 --- a/lib/launchy/detect/nix_desktop_environment.rb +++ b/lib/launchy/detect/nix_desktop_environment.rb @@ -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 diff --git a/lib/launchy/detect/runner.rb b/lib/launchy/detect/runner.rb index ab06eab..3a833a7 100644 --- a/lib/launchy/detect/runner.rb +++ b/lib/launchy/detect/runner.rb @@ -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 diff --git a/spec/application_spec.rb b/spec/application_spec.rb index ea18e2f..27c8fe0 100644 --- a/spec/application_spec.rb +++ b/spec/application_spec.rb @@ -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 diff --git a/spec/applications/browser_spec.rb b/spec/applications/browser_spec.rb index 497350d..000d2ef 100644 --- a/spec/applications/browser_spec.rb +++ b/spec/applications/browser_spec.rb @@ -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 @@ -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 @@ -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 diff --git a/spec/cli_spec.rb b/spec/cli_spec.rb index 61c57c6..5913ba1 100644 --- a/spec/cli_spec.rb +++ b/spec/cli_spec.rb @@ -21,9 +21,9 @@ def cli_test( argv, env, exit_val, stderr_regex, stdout_regex ) begin Launchy::Cli.new.run( argv, env ) rescue SystemExit => se - se.status.must_equal exit_val - $stderr.string.must_match stderr_regex if stderr_regex - $stdout.string.must_match stdout_regex if stdout_regex + _(se.status).must_equal exit_val + _($stderr.string).must_match stderr_regex if stderr_regex + _($stdout.string).must_match stdout_regex if stdout_regex end end @@ -47,14 +47,14 @@ def cli_test( argv, env, exit_val, stderr_regex, stdout_regex ) l = Launchy::Cli.new argv = %w[ --debug --dry-run http://github.com/copiousfreetime/launchy ] l.parse( argv , {} ) - argv.size.must_equal 1 - argv[0].must_equal "http://github.com/copiousfreetime/launchy" + _(argv.size).must_equal 1 + _(argv[0]).must_equal "http://github.com/copiousfreetime/launchy" end it "prints the command on stdout when using --dry-run" do argv = %w[ --debug --dry-run http://github.com/copiousfreetime/launchy ] Launchy::Cli.new.good_run( argv, {} ) - $stdout.string.must_match %r[github.com] + _($stdout.string).must_match %r[github.com] end { @@ -65,10 +65,10 @@ def cli_test( argv, env, exit_val, stderr_regex, stdout_regex ) argv = [ opt, val[1], "http://github.com/copiousfreetime/launchy" ] l = Launchy::Cli.new rc = l.parse( argv, {} ) - rc.must_equal true - argv.size.must_equal 1 - argv[0].must_equal "http://github.com/copiousfreetime/launchy" - l.options[val[0]].must_equal val[1] + _(rc).must_equal true + _(argv.size).must_equal 1 + _(argv[0]).must_equal "http://github.com/copiousfreetime/launchy" + _(l.options[val[0]]).must_equal val[1] end end end diff --git a/spec/detect/host_os_family_spec.rb b/spec/detect/host_os_family_spec.rb index 36c149d..33ff056 100644 --- a/spec/detect/host_os_family_spec.rb +++ b/spec/detect/host_os_family_spec.rb @@ -13,7 +13,8 @@ YAML::load( IO.read( File.expand_path( "../../tattle-host-os.yaml", __FILE__ ) ) )['host_os'].keys.sort.each do |os| it "OS family of #{os} is detected" do - Launchy::Detect::HostOsFamily.detect( os ).must_be_kind_of Launchy::Detect::HostOsFamily + os_family = Launchy::Detect::HostOsFamily.detect( os ) + _(os_family).must_be_kind_of Launchy::Detect::HostOsFamily end end @@ -22,19 +23,20 @@ 'linux' => :nix?, 'cygwin' => :cygwin? }.each_pair do |os, method| it "#{method} returns true for #{os} " do - Launchy::Detect::HostOsFamily.detect( os ).send( method ).must_equal true + r = Launchy::Detect::HostOsFamily.detect( os ).send( method ) + _(r).must_equal true end end it "uses the global host_os overrides" do ENV['LAUNCHY_HOST_OS'] = "fake-os-2" - lambda { Launchy::Detect::HostOsFamily.detect }.must_raise Launchy::Detect::HostOsFamily::NotFoundError + _(lambda { Launchy::Detect::HostOsFamily.detect }).must_raise Launchy::Detect::HostOsFamily::NotFoundError ENV.delete('LAUNCHY_HOST_OS') end it "does not find an os of 'dos'" do - lambda { Launchy::Detect::HostOsFamily.detect( 'dos' ) }.must_raise Launchy::Detect::HostOsFamily::NotFoundError + _(lambda { Launchy::Detect::HostOsFamily.detect( 'dos' ) }).must_raise Launchy::Detect::HostOsFamily::NotFoundError end end diff --git a/spec/detect/host_os_spec.rb b/spec/detect/host_os_spec.rb index c6de254..53ffcff 100644 --- a/spec/detect/host_os_spec.rb +++ b/spec/detect/host_os_spec.rb @@ -3,16 +3,16 @@ describe Launchy::Detect::HostOs do it "uses the defult host os from ruby's config" do - Launchy::Detect::HostOs.new.host_os.must_equal RbConfig::CONFIG['host_os'] + _(Launchy::Detect::HostOs.new.host_os).must_equal RbConfig::CONFIG['host_os'] end it "uses the passed in value as the host os" do - Launchy::Detect::HostOs.new( "fake-os-1").host_os.must_equal "fake-os-1" + _(Launchy::Detect::HostOs.new( "fake-os-1").host_os).must_equal "fake-os-1" end it "uses the environment variable LAUNCHY_HOST_OS to override ruby's config" do ENV['LAUNCHY_HOST_OS'] = "fake-os-2" - Launchy::Detect::HostOs.new.host_os.must_equal "fake-os-2" + _(Launchy::Detect::HostOs.new.host_os).must_equal "fake-os-2" ENV.delete('LAUNCHY_HOST_OS') end diff --git a/spec/detect/nix_desktop_environment_spec.rb b/spec/detect/nix_desktop_environment_spec.rb index 2f084d4..42472fa 100644 --- a/spec/detect/nix_desktop_environment_spec.rb +++ b/spec/detect/nix_desktop_environment_spec.rb @@ -12,15 +12,16 @@ it "returns false for XFCE if xprop is not found" do Launchy.host_os = "linux" - Launchy::Detect::NixDesktopEnvironment::Xfce.is_current_desktop_environment?.must_equal( false ) + _(Launchy::Detect::NixDesktopEnvironment::Xfce.is_current_desktop_environment?).must_equal( false ) end it "returns NotFound if it cannot determine the *nix desktop environment" do Launchy.host_os = "linux" ENV.delete( "KDE_FULL_SESSION" ) ENV.delete( "GNOME_DESKTOP_SESSION_ID" ) + Launchy.path = %w[ / /tmp ].join(File::PATH_SEPARATOR) not_found = Launchy::Detect::NixDesktopEnvironment.detect - not_found.must_equal( Launchy::Detect::NixDesktopEnvironment::NotFound ) - not_found.browser.must_equal( Launchy::Argv.new ) + _(not_found).must_equal( Launchy::Detect::NixDesktopEnvironment::NotFound ) + _(not_found.browser).must_equal( Launchy::Argv.new ) end end diff --git a/spec/detect/ruby_engine_spec.rb b/spec/detect/ruby_engine_spec.rb index e77b071..17c9373 100644 --- a/spec/detect/ruby_engine_spec.rb +++ b/spec/detect/ruby_engine_spec.rb @@ -12,18 +12,18 @@ %w[ ruby jruby rbx macruby ].each do |ruby| it "detects the #{ruby} RUBY_ENGINE" do - Launchy::Detect::RubyEngine.detect( ruby ).ancestors.must_include Launchy::Detect::RubyEngine + _(Launchy::Detect::RubyEngine.detect( ruby ).ancestors).must_include Launchy::Detect::RubyEngine end end it "uses the global ruby_engine overrides" do ENV['LAUNCHY_RUBY_ENGINE'] = "rbx" - Launchy::Detect::RubyEngine.detect.must_equal Launchy::Detect::RubyEngine::Rbx + _(Launchy::Detect::RubyEngine.detect).must_equal Launchy::Detect::RubyEngine::Rbx ENV.delete('LAUNCHY_RUBY_ENGINE') end it "does not find a ruby engine of 'foo'" do - lambda { Launchy::Detect::RubyEngine.detect( 'foo' ) }.must_raise Launchy::Detect::RubyEngine::NotFoundError + _(lambda { Launchy::Detect::RubyEngine.detect( 'foo' ) }).must_raise Launchy::Detect::RubyEngine::NotFoundError end { 'rbx' => :rbx?, @@ -31,7 +31,7 @@ 'macruby' => :macruby?, 'jruby' => :jruby? }.each_pair do |engine, method| it "#{method} returns true for #{engine} " do - Launchy::Detect::RubyEngine.detect( engine ).send( method ).must_equal true + _(Launchy::Detect::RubyEngine.detect( engine ).send( method )).must_equal true end end end diff --git a/spec/detect/runner_spec.rb b/spec/detect/runner_spec.rb index 78aef82..c323f36 100644 --- a/spec/detect/runner_spec.rb +++ b/spec/detect/runner_spec.rb @@ -13,17 +13,17 @@ it "raises an error when there is an unknown host os" do Launchy.host_os = "foo" - lambda{ Launchy::Detect::Runner.detect }.must_raise Launchy::Detect::HostOsFamily::NotFoundError + _(lambda{ Launchy::Detect::Runner.detect }).must_raise Launchy::Detect::HostOsFamily::NotFoundError end it "raises an error when there is an unknown ruby engine" do Launchy.ruby_engine = "wibble" - lambda{ Launchy::Detect::Runner.detect }.must_raise Launchy::Detect::RubyEngine::NotFoundError + _(lambda{ Launchy::Detect::Runner.detect }).must_raise Launchy::Detect::RubyEngine::NotFoundError end it "raises and error when there is no command found" do runner = Launchy::Detect::Runner.detect - lambda{ runner.run( nil, *%w[ arg1 arg2 arg 3] ) }.must_raise Launchy::CommandNotFoundError + _(lambda{ runner.run( nil, *%w[ arg1 arg2 arg 3] ) }).must_raise Launchy::CommandNotFoundError end # On anything that has fork, use Forkable @@ -33,7 +33,7 @@ Launchy.host_os = host_os Launchy.ruby_engine = engine_name engine = Launchy::Detect::Runner.detect - engine.must_be_instance_of Launchy::Detect::Runner::Forkable + _(engine).must_be_instance_of Launchy::Detect::Runner::Forkable end end end @@ -48,7 +48,7 @@ Launchy.host_os = host_os Launchy.ruby_engine = 'jruby' engine = Launchy::Detect::Runner.detect - engine.must_be_instance_of runner + _(engine).must_be_instance_of runner end end @@ -58,14 +58,14 @@ Launchy.host_os = "mingw" Launchy.ruby_engine = engine_name e = Launchy::Detect::Runner.detect - e.must_be_instance_of Launchy::Detect::Runner::Windows + _(e).must_be_instance_of Launchy::Detect::Runner::Windows end end it "Windows launches use the 'cmd' command" do win = Launchy::Detect::Runner::Windows.new cmd = win.dry_run( "not-really", [ "http://example.com" ] ) - cmd.must_equal 'cmd /c not-really http://example.com' + _(cmd).must_equal 'cmd /c not-really http://example.com' end %w[ & | ( ) < > ^ ].each do |reserved_char| @@ -75,29 +75,29 @@ url = parts.join( reserved_char ) output_url = parts.join( "^#{reserved_char}" ) - win.all_args( "not-really", [ url ] ).must_equal [ 'cmd', '/c', 'not-really', output_url ] + _(win.all_args( "not-really", [ url ] )).must_equal [ 'cmd', '/c', 'not-really', output_url ] cmd = win.dry_run( "not-really", [ url ] ) - cmd.must_equal "cmd /c not-really #{output_url}" + _(cmd).must_equal "cmd /c not-really #{output_url}" end end it "Jruby doesnot escapes '&' in urls" do jruby = Launchy::Detect::Runner::Jruby.new cmd = jruby.dry_run( "not-really", [ @test_url ]) - cmd.must_equal 'not-really http://example.com/?foo=bar&baz=wibble' + _(cmd).must_equal 'not-really http://example.com/?foo=bar&baz=wibble' end it "does not escape %38 items in urls" do l = Launchy::Detect::Runner::Forkable.new cmd = l.dry_run( "not-really", [ "http://ja.wikipedia.org/wiki/%E3%81%82" ] ) - cmd.must_equal( 'not-really http://ja.wikipedia.org/wiki/%E3%81%82' ) + _(cmd).must_equal( 'not-really http://ja.wikipedia.org/wiki/%E3%81%82' ) end it "can launch a utf8 url" do url = "http://ja.wikipedia.org/wiki/あ" l = Launchy::Detect::Runner::Forkable.new cmd = l.dry_run( "not-really", [ url ] ) - cmd.must_equal( "not-really #{url}" ) + _(cmd).must_equal( "not-really #{url}" ) end end diff --git a/spec/launchy_spec.rb b/spec/launchy_spec.rb index 2f32b26..0138084 100644 --- a/spec/launchy_spec.rb +++ b/spec/launchy_spec.rb @@ -23,7 +23,7 @@ old_stderr = $stderr $stderr = StringIO.new Launchy.log "This is a test log message" - $stderr.string.strip.must_equal "LAUNCHY_DEBUG: This is a test log message" + _($stderr.string.strip).must_equal "LAUNCHY_DEBUG: This is a test log message" $stderr = old_stderr ENV["LAUNCHY_DEBUG"] = nil end @@ -31,87 +31,89 @@ it "sets the global option :dry_run to true if LAUNCHY_DRY_RUN environment variable is 'true'" do ENV['LAUNCHY_DRY_RUN'] = 'true' Launchy.extract_global_options({}) - Launchy.dry_run?.must_equal true + _(Launchy.dry_run?).must_equal true ENV['LAUNCHY_DRY_RUN'] = nil end it "sets the global option :debug to true if LAUNCHY_DEBUG environment variable is 'true'" do ENV['LAUNCHY_DEBUG'] = 'true' Launchy.extract_global_options({}) - Launchy.debug?.must_equal true + _(Launchy.debug?).must_equal true ENV['LAUNCHY_DEBUG'] = nil end it "has the global option :debug" do Launchy.extract_global_options( { :debug => 'true' } ) - Launchy.debug?.must_equal true + _(Launchy.debug?).must_equal true Launchy.extract_global_options( { :debug => true } ) - Launchy.debug?.must_equal true + _(Launchy.debug?).must_equal true end it "has the global option :dry_run" do Launchy.extract_global_options( { :dry_run => 'true' } ) - Launchy.dry_run?.must_equal true + _(Launchy.dry_run?).must_equal true Launchy.extract_global_options( { :dry_run => true } ) - Launchy.dry_run?.must_equal true + _(Launchy.dry_run?).must_equal true end it "has the global option :application" do Launchy.extract_global_options( { :application => "wibble" } ) - Launchy.application.must_equal 'wibble' + _(Launchy.application).must_equal 'wibble' end it "has the global option :host_os" do Launchy.extract_global_options( { :host_os => "my-special-os-v2" } ) - Launchy.host_os.must_equal 'my-special-os-v2' + _(Launchy.host_os).must_equal 'my-special-os-v2' end it "has the global option :ruby_engine" do Launchy.extract_global_options( { :ruby_engine => "myruby" } ) - Launchy.ruby_engine.must_equal 'myruby' + _(Launchy.ruby_engine).must_equal 'myruby' end it "raises an exception if no scheme is found for the given uri" do - lambda { Launchy.open( @invalid_url ) }.must_raise Launchy::ApplicationNotFoundError + _(lambda { Launchy.open( @invalid_url ) }).must_raise Launchy::ApplicationNotFoundError end it "asssumes we open a local file if we have an exception if we have an invalid scheme and a valid path" do uri = "blah://example.com/#{__FILE__}" Launchy.open( uri , :dry_run => true ) - $stdout.string.strip.must_equal "/usr/bin/open #{uri}" + parts = $stdout.string.strip.split + _(parts.size).must_be :>, 1 + _(parts.last).must_equal uri end it "opens a local file if we have a drive letter and a valid path on windows" do uri = "C:#{__FILE__}" Launchy.open( uri, :dry_run => true, :host_os => 'windows' ) - $stdout.string.strip.must_equal 'cmd /c start "launchy" /b ' + uri + _($stdout.string.strip).must_equal 'cmd /c start "launchy" /b ' + uri end it "calls the block if instead of raising an exception if there is an error" do Launchy.open( @invalid_url ) { $stderr.puts "oops had an error opening #{@invalid_url}" } - $stderr.string.strip.must_equal "oops had an error opening #{@invalid_url}" + _($stderr.string.strip).must_equal "oops had an error opening #{@invalid_url}" end it "calls the block with the values passed to launchy and the error" do options = { :dry_run => true } Launchy.open( @invalid_url, :dry_run => true ) { |e| $stderr.puts "had an error opening #{@invalid_url} with options #{options}: #{e}" } - $stderr.string.strip.must_equal "had an error opening #{@invalid_url} with options #{options}: No application found to handle '#{@invalid_url}'" + _($stderr.string.strip).must_equal "had an error opening #{@invalid_url} with options #{options}: No application found to handle '#{@invalid_url}'" end it "raises the error in the called block" do - lambda { Launchy.open( @invalid_url ) { raise StandardError, "KABOOM!" } }.must_raise StandardError + _(lambda { Launchy.open( @invalid_url ) { raise StandardError, "KABOOM!" } }).must_raise StandardError end [ 'www.example.com', 'www.example.com/foo/bar', "C:#{__FILE__}" ].each do |x| it "picks a Browser for #{x}" do app = Launchy.app_for_uri_string( x ) - app.must_equal( Launchy::Application::Browser ) + _(app).must_equal( Launchy::Application::Browser ) end end it "can use a Pathname as the URI" do path = Pathname.new( Dir.pwd ) app = Launchy.app_for_uri_string( path ) - app.must_equal( Launchy::Application::Browser ) + _(app).must_equal( Launchy::Application::Browser ) end end diff --git a/spec/version_spec.rb b/spec/version_spec.rb index d67a0d8..291e2ad 100644 --- a/spec/version_spec.rb +++ b/spec/version_spec.rb @@ -2,10 +2,10 @@ describe 'Launchy::VERSION' do it "should have a #.#.# format" do - Launchy::VERSION.must_match( /\d+\.\d+\.\d+/ ) - Launchy::Version.to_s.must_match( /\d+\.\d+\.\d+/ ) + _(Launchy::VERSION).must_match( /\d+\.\d+\.\d+/ ) + _(Launchy::Version.to_s).must_match( /\d+\.\d+\.\d+/ ) Launchy::Version.to_a.each do |n| - n.to_i.must_be :>=, 0 + _(n.to_i).must_be :>=, 0 end end end diff --git a/tasks/default.rake b/tasks/default.rake index 80ee6ad..fef74b7 100644 --- a/tasks/default.rake +++ b/tasks/default.rake @@ -24,12 +24,12 @@ namespace :develop do File.open( "Gemfile", "w+" ) do |f| f.puts "# DO NOT EDIT - This file is automatically generated" f.puts "# Make changes to Manifest.txt and/or Rakefile and regenerate" - f.puts 'source "https://rubygems.org/"' + f.puts 'source "https://rubygems.org"' f.puts 'gemspec' end end end -desc "Boostrap development" +desc "Bootstrap development" task :develop => "develop:default" #------------------------------------------------------------------------------ @@ -38,7 +38,7 @@ task :develop => "develop:default" begin require 'rake/testtask' Rake::TestTask.new( :test ) do |t| - t.ruby_opts = %w[ -w -rubygems ] + t.ruby_opts = %w[ -w ] t.libs = %w[ lib spec test ] t.pattern = "{test,spec}/**/{test_*,*_spec}.rb" end diff --git a/tasks/this.rb b/tasks/this.rb index 6d713b1..67eb531 100644 --- a/tasks/this.rb +++ b/tasks/this.rb @@ -28,7 +28,7 @@ def initialize(&block) @exclude_from_manifest = Regexp.union(/\.(git|DS_Store)/, /^(doc|coverage|pkg|tmp|Gemfile(\.lock)?)/, /^[^\/]+\.gemspec/, - /\.(swp|jar|bundle|so|rvmrc|travis.yml)$/, + /\.(swp|jar|bundle|so|rvmrc|travis.yml|byebug_history)$/, /~$/) @gemspecs = Hash.new yield self if block_given? @@ -146,7 +146,7 @@ def core_gemspec spec.rdoc_options = [ "--main" , 'README.md', "--markup", "tomdoc" ] - spec.required_ruby_version = '>= 1.9.3' + spec.required_ruby_version = '>= 2.4.0' end end @@ -194,7 +194,9 @@ def description end def license - "ISC" + license_file = project_path("LICENSE") + line = license_file.readlines.first + line.split(/\s+/).first end # Internal: The path to the gemspec file