pax_global_header00006660000000000000000000000064136114213770014517gustar00rootroot0000000000000052 comment=6a9f19f897e7c0dc43e30d43a51108e9b8f4f6e6 tty-which-0.4.2/000077500000000000000000000000001361142137700134425ustar00rootroot00000000000000tty-which-0.4.2/.github/000077500000000000000000000000001361142137700150025ustar00rootroot00000000000000tty-which-0.4.2/.github/FUNDING.yml000066400000000000000000000000241361142137700166130ustar00rootroot00000000000000github: piotrmurach tty-which-0.4.2/.github/ISSUE_TEMPLATE.md000066400000000000000000000011051361142137700175040ustar00rootroot00000000000000### Are you in the right place? * For issues or feature requests file a GitHub issue in this repository * For general questions or discussion post in [Gitter](https://gitter.im/piotrmurach/tty) ### Describe the problem A brief description of the issue/feature. ### Steps to reproduce the problem ``` Your code here to reproduce the issue ``` ### Actual behaviour What happened? This could be a description, log output, error raised etc... ### Expected behaviour What did you expect to happen? ### Describe your environment * OS version: * Ruby version: * TTY::Which version: tty-which-0.4.2/.github/PULL_REQUEST_TEMPLATE.md000066400000000000000000000006761361142137700206140ustar00rootroot00000000000000### Describe the change What does this Pull Request do? ### Why are we doing this? Any related context as to why is this is a desirable change. ### Benefits How will the library improve? ### Drawbacks Possible drawbacks applying this change. ### Requirements Put an X between brackets on each line if you have done the item: [] Tests written & passing locally? [] Code style checked? [] Rebased with `master` branch? [] Documentaion updated? tty-which-0.4.2/.gitignore000066400000000000000000000002711361142137700154320ustar00rootroot00000000000000*.gem *.rbc .bundle .config .yardoc Gemfile.lock InstalledFiles _yardoc coverage doc/ lib/bundler/man pkg rdoc spec/reports test/tmp test/version_tmp tmp *.bundle *.so *.o *.a mkmf.log tty-which-0.4.2/.rspec000066400000000000000000000000511361142137700145530ustar00rootroot00000000000000--color --require spec_helper --warnings tty-which-0.4.2/.travis.yml000066400000000000000000000006211361142137700155520ustar00rootroot00000000000000--- language: ruby before_install: "gem install bundler -v '< 2.0'" script: "bundle exec rake ci" rvm: - 2.0.0 - 2.1.10 - 2.2.10 - 2.3.8 - 2.4.9 - 2.5.7 - 2.6.5 - 2.7.0 - ruby-head - jruby-9.2.6.0 - jruby-head matrix: allow_failures: - rvm: ruby-head - rvm: jruby-9.2.6.0 - rvm: jruby-head fast_finish: true branches: only: master notifications: email: false tty-which-0.4.2/CHANGELOG.md000066400000000000000000000034311361142137700152540ustar00rootroot00000000000000# Change log ## [v0.4.2] - 2020-01-20 ### Changed * Change gemspec to add metadata and remove test artifacts ## [v0.4.1] - 2019-06-02 ### Changed * Change to relax bundler dependency version ## [v0.4.0] - 2018-10-13 ### Added * Add ability to specify search paths for #which and #exist? calls ### Changed * Change to freeze all strings * Change gemspec to require Ruby >= 2.0.0 * Change gemspec to load files without calling git * Change gemspec to add rspec as dev dependency ## [v0.3.0] - 2017-03-20 ### Changed * Change #extensions to use file path separator * Change files loading * Remove search paths caching ## [v0.2.2] - 2017-02-06 ### Fixed * Fix File namespacing issue ## [v0.2.1] - 2016-12-26 ### Changed * Change to stop shadowing path var in Which#search_paths ## [v0.2.0] - 2016-07-01 ### Added * Add Which#exist? to check if file exists based on found path ### Changed * Change Which#search_paths to allow for paths argument * Rename Which#executable_file_with_ext? to #file_with_exec_ext? * Rename Which#path_with_executable_file? to #file_with_path? ### Fixed * Fix bug with Which#file_with_exec_ext? when comparing extensions ## [v0.1.0] - 2015-05-30 * Initial implementation and release [v0.4.2]: https://github.com/piotrmurach/tty-which/compare/v0.4.1...v0.4.2 [v0.4.1]: https://github.com/piotrmurach/tty-which/compare/v0.4.0...v0.4.1 [v0.4.0]: https://github.com/piotrmurach/tty-which/compare/v0.3.0...v0.4.0 [v0.3.0]: https://github.com/piotrmurach/tty-which/compare/v0.2.2...v0.3.0 [v0.2.2]: https://github.com/piotrmurach/tty-which/compare/v0.2.1...v0.2.2 [v0.2.1]: https://github.com/piotrmurach/tty-which/compare/v0.2.0...v0.2.1 [v0.2.0]: https://github.com/piotrmurach/tty-which/compare/v0.1.0...v0.2.0 [v0.1.0]: https://github.com/piotrmurach/tty-which/compare/v0.1.0 tty-which-0.4.2/CODE_OF_CONDUCT.md000066400000000000000000000062351361142137700162470ustar00rootroot00000000000000# Contributor Covenant Code of Conduct ## Our Pledge In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation. ## Our Standards Examples of behavior that contributes to creating a positive environment include: * Using welcoming and inclusive language * Being respectful of differing viewpoints and experiences * Gracefully accepting constructive criticism * Focusing on what is best for the community * Showing empathy towards other community members Examples of unacceptable behavior by participants include: * The use of sexualized language or imagery and unwelcome sexual attention or advances * Trolling, insulting/derogatory comments, and personal or political attacks * Public or private harassment * Publishing others' private information, such as a physical or electronic address, without explicit permission * Other conduct which could reasonably be considered inappropriate in a professional setting ## Our Responsibilities Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior. Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful. ## Scope This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers. ## Enforcement Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at piotr@piotrmurach.com. All complaints will be reviewed and investigated and will result in a response that is deemed necessary and appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately. Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership. ## Attribution This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version] [homepage]: http://contributor-covenant.org [version]: http://contributor-covenant.org/version/1/4/ tty-which-0.4.2/Gemfile000066400000000000000000000002561361142137700147400ustar00rootroot00000000000000source 'https://rubygems.org' gemspec group :test do gem 'simplecov', '~> 0.16.1' gem 'coveralls', '~> 0.8.22' end group :metrics do gem 'yardstick', '~> 0.9.9' end tty-which-0.4.2/LICENSE.txt000066400000000000000000000020551361142137700152670ustar00rootroot00000000000000Copyright (c) 2015 Piotr Murach MIT License Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. tty-which-0.4.2/README.md000066400000000000000000000061761361142137700147330ustar00rootroot00000000000000
tty logo
# TTY::Which [![Gitter](https://badges.gitter.im/Join%20Chat.svg)][gitter] [![Gem Version](https://badge.fury.io/rb/tty-which.svg)][gem] [![Build Status](https://secure.travis-ci.org/piotrmurach/tty-which.svg?branch=master)][travis] [![Build status](https://ci.appveyor.com/api/projects/status/2rpm67huf1nh98d0?svg=true)][appveyor] [![Code Climate](https://codeclimate.com/github/piotrmurach/tty-which/badges/gpa.svg)][codeclimate] [![Coverage Status](https://coveralls.io/repos/github/piotrmurach/tty-which/badge.svg?branch=master)][coveralls] [![Inline docs](http://inch-ci.org/github/piotrmurach/tty-which.svg?branch=master)][inchpages] [gitter]: https://gitter.im/piotrmurach/tty [gem]: http://badge.fury.io/rb/tty-which [travis]: http://travis-ci.org/piotrmurach/tty-which [appveyor]: https://ci.appveyor.com/project/piotrmurach/tty-which [codeclimate]: https://codeclimate.com/github/piotrmurach/tty-which [coveralls]: https://coveralls.io/github/piotrmurach/tty-which [inchpages]: http://inch-ci.org/github/piotrmurach/tty-which > Platform independent implementation of Unix `which` utility that searches for executable file in the path variable. **TTY::Which** provides cross-platform executables search component for [TTY](https://github.com/piotrmurach/tty) toolkit. ## Installation Add this line to your application's Gemfile: gem 'tty-which' And then execute: $ bundle Or install it yourself as: $ gem install tty-which ## Usage **TTY::Which** has `which` method that searches set of directories for an executable file based on the `PATH` environment variable. When the path to an executable program exists, an absolute path is returned, otherwise `nil`. For example, to find location for an executable program do: ```ruby TTY::Which.which('less') # => '/usr/bin/less' TTY::Which.which('git') # => 'C:\Program Files\Git\bin\git' ``` You can also check an absolute path to executable: ```ruby TTY::Which.which('/usr/bin/ruby') # => '/usr/bin/ruby' ``` You can also specify directly the paths to search using `:paths` keyword: ```ruby TTY::Which.which('ruby', paths: ['/usr/local/bin', '/usr/bin', '/bin']) # => '/usr/local/bin/ruby' ``` When you're only interesting in knowing that an executable exists on the system use the `exist?` call: ```ruby TTY::Which.exist?('ruby') # => true ``` ## Contributing Bug reports and pull requests are welcome on GitHub at https://github.com/piotrmurach/tty-which. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct. 1. Fork it ( https://github.com/piotrmurach/tty-which/fork ) 2. Create your feature branch (`git checkout -b my-new-feature`) 3. Commit your changes (`git commit -am 'Add some feature'`) 4. Push to the branch (`git push origin my-new-feature`) 5. Create a new Pull Request ## Copyright Copyright (c) 2015 Piotr Murach. See LICENSE for further details. tty-which-0.4.2/Rakefile000066400000000000000000000002171361142137700151070ustar00rootroot00000000000000require 'bundler/gem_tasks' FileList['tasks/**/*.rake'].each(&method(:import)) desc 'Run all specs' task ci: %w[ spec ] task default: :spec tty-which-0.4.2/appveyor.yml000066400000000000000000000011461361142137700160340ustar00rootroot00000000000000--- install: - SET PATH=C:\Ruby%ruby_version%\bin;%PATH% - gem install bundler -v '< 2.0' - bundle install before_test: - ruby -v - gem -v - bundle -v build: off test_script: - bundle exec rake ci environment: matrix: - ruby_version: "200" - ruby_version: "200-x64" - ruby_version: "21" - ruby_version: "21-x64" - ruby_version: "22" - ruby_version: "22-x64" - ruby_version: "23" - ruby_version: "23-x64" - ruby_version: "24" - ruby_version: "24-x64" - ruby_version: "25" - ruby_version: "25-x64" - ruby_version: "26" - ruby_version: "26-x64" tty-which-0.4.2/lib/000077500000000000000000000000001361142137700142105ustar00rootroot00000000000000tty-which-0.4.2/lib/tty-which.rb000066400000000000000000000000351361142137700164530ustar00rootroot00000000000000require_relative 'tty/which' tty-which-0.4.2/lib/tty/000077500000000000000000000000001361142137700150305ustar00rootroot00000000000000tty-which-0.4.2/lib/tty/which.rb000066400000000000000000000105211361142137700164560ustar00rootroot00000000000000# frozen_string_literal: true require_relative 'which/version' module TTY # A class responsible for finding an executable in the PATH module Which # Find an executable in a platform independent way # # @param [String] command # the command to search for # @param [Array[String]] paths # the paths to look through # # @example # which('ruby') # => '/usr/local/bin/ruby' # which('/usr/local/bin/ruby') # => '/usr/local/bin/ruby' # which('foo') # => nil # # @example # which('ruby', paths: ['/usr/locale/bin', '/usr/bin', '/bin']) # # @return [String, nil] # the absolute path to executable if found, `nil` otherwise # # @api public def which(cmd, paths: search_paths) if file_with_path?(cmd) return cmd if executable_file?(cmd) extensions.each do |ext| exe = ::File.join(cmd, ext) return ::File.absolute_path(exe) if executable_file?(exe) end return nil end paths.each do |path| if file_with_exec_ext?(cmd) exe = ::File.join(path, cmd) return ::File.absolute_path(exe) if executable_file?(exe) end extensions.each do |ext| exe = ::File.join(path, "#{cmd}#{ext}") return ::File.absolute_path(exe) if executable_file?(exe) end end nil end module_function :which # Check if executable exists in the path # # @param [String] command # the executable to check # # @param [String] paths # paths to check # # @return [Boolean] # # @api public def exist?(cmd, paths: search_paths) !which(cmd, paths: paths).nil? end module_function :exist? # Find default system paths # # @param [String] path # the path to search through # # @example # search_paths("/usr/local/bin:/bin") # # => ['/bin'] # # @return [Array[String]] # the array of paths to search # # @api private def search_paths(path = ENV['PATH']) paths = if path && !path.empty? path.split(::File::PATH_SEPARATOR) else %w(/usr/local/bin /usr/ucb /usr/bin /bin) end paths.select(&Dir.method(:exist?)) end module_function :search_paths # All possible file extensions # # @example # extensions('.exe;cmd;.bat') # # => ['.exe','.bat'] # # @param [String] path_ext # a string of semicolon separated filename extensions # # @return [Array[String]] # an array with valid file extensions # # @api private def extensions(path_ext = ENV['PATHEXT']) return [''] unless path_ext path_ext.split(::File::PATH_SEPARATOR).select { |part| part.include?('.') } end module_function :extensions # Determines if filename is an executable file # # @example Basic usage # executable_file?('/usr/bin/less') # => true # # @example Executable in directory # executable_file?('less', '/usr/bin') # => true # executable_file?('less', '/usr') # => false # # @param [String] filename # the path to file # @param [String] dir # the directory within which to search for filename # # @return [Boolean] # # @api private def executable_file?(filename, dir = nil) path = ::File.join(dir, filename) if dir path ||= filename ::File.file?(path) && ::File.executable?(path) end module_function :executable_file? # Check if command itself has executable extension # # @param [String] filename # the path to executable file # # @example # file_with_exec_ext?("file.bat") # # => true # # @return [Boolean] # # @api private def file_with_exec_ext?(filename) extension = ::File.extname(filename) return false if extension.empty? extensions.any? { |ext| extension.casecmp(ext).zero? } end module_function :file_with_exec_ext? # Check if executable file is part of absolute/relative path # # @param [String] cmd # the executable to check # # @return [Boolean] # # @api private def file_with_path?(cmd) ::File.expand_path(cmd) == cmd end module_function :file_with_path? end # Which end # TTY tty-which-0.4.2/lib/tty/which/000077500000000000000000000000001361142137700161325ustar00rootroot00000000000000tty-which-0.4.2/lib/tty/which/version.rb000066400000000000000000000001471361142137700201460ustar00rootroot00000000000000# frozen_string_literal: true module TTY module Which VERSION = "0.4.2" end # Which end # TTY tty-which-0.4.2/spec/000077500000000000000000000000001361142137700143745ustar00rootroot00000000000000tty-which-0.4.2/spec/spec_helper.rb000066400000000000000000000020401361142137700172060ustar00rootroot00000000000000# frozen_string_literal: true if RUBY_VERSION > '1.9' and (ENV['COVERAGE'] || ENV['TRAVIS']) require 'simplecov' require 'coveralls' SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[ SimpleCov::Formatter::HTMLFormatter, Coveralls::SimpleCov::Formatter ] SimpleCov.start do command_name 'spec' add_filter 'spec' end end require 'tty-which' RSpec.configure do |config| config.expect_with :rspec do |expectations| expectations.include_chain_clauses_in_custom_matcher_descriptions = true end config.mock_with :rspec do |mocks| mocks.verify_partial_doubles = true end # Limits the available syntax to the non-monkey patched syntax that is recommended. config.disable_monkey_patching! # This setting enables warnings. It's recommended, but in some cases may # be too noisy due to issues in dependencies. config.warnings = true if config.files_to_run.one? config.default_formatter = 'doc' end config.profile_examples = 2 config.order = :random Kernel.srand config.seed end tty-which-0.4.2/spec/unit/000077500000000000000000000000001361142137700153535ustar00rootroot00000000000000tty-which-0.4.2/spec/unit/executable_file_spec.rb000066400000000000000000000007141361142137700220340ustar00rootroot00000000000000# frozen_string_literal: true RSpec.describe TTY::Which, '#executable_file?' do it "checks if file is executable" do allow(::File).to receive(:join).with('/usr/local/bin', 'ruby'). and_return('/usr/local/bin/ruby') allow(::File).to receive(:file?).and_return(true) allow(::File).to receive(:executable?).with('/usr/local/bin/ruby').and_return(true) expect(TTY::Which.executable_file?('ruby', '/usr/local/bin')).to eq(true) end end tty-which-0.4.2/spec/unit/exist_spec.rb000066400000000000000000000007551361142137700200550ustar00rootroot00000000000000# frozen_string_literal: true RSpec.describe TTY::Which, '#exist?' do it "finds executable in the path" do allow(TTY::Which).to receive(:which).with('ruby', a_hash_including(:paths)). and_return('/usr/loca/bin/ruby') expect(TTY::Which.exist?('ruby')).to be(true) end it "fails to find executable in the path" do allow(TTY::Which).to receive(:which).with('ruby', a_hash_including(:paths)).and_return(nil) expect(TTY::Which.exist?('ruby')).to be(false) end end tty-which-0.4.2/spec/unit/extensions_spec.rb000066400000000000000000000007561361142137700211210ustar00rootroot00000000000000# frozen_string_literal: true RSpec.describe TTY::Which, '#extensions' do it "provides extensions" do exts = [".COM", ".EXE", ".BAT", ".CMD", ".VBS", ".RB", ".RBW"] exts_path = exts.join(::File::PATH_SEPARATOR) allow(ENV).to receive(:[]).with('PATHEXT').and_return(exts_path) expect(TTY::Which.extensions).to eq(exts) end it "finds no extensions" do allow(ENV).to receive(:[]).with('PATHEXT').and_return(nil) expect(TTY::Which.extensions).to eq(['']) end end tty-which-0.4.2/spec/unit/file_with_exec_ext_spec.rb000066400000000000000000000010271361142137700225500ustar00rootroot00000000000000# frozen_string_literal: true RSpec.describe TTY::Which, "#file_with_exec_ext?" do it "detects executable extension" do filename = 'file.exe' allow(TTY::Which).to receive(:extensions).and_return(['.EXE', '.BAT', '.CMD']) expect(TTY::Which.file_with_exec_ext?(filename)).to eq(true) end it "fails to detect executable extension" do filename = 'file.unknown' allow(TTY::Which).to receive(:extensions).and_return(['.EXE', '.BAT']) expect(TTY::Which.file_with_exec_ext?(filename)).to eq(false) end end tty-which-0.4.2/spec/unit/search_paths_spec.rb000066400000000000000000000016511361142137700213610ustar00rootroot00000000000000# frozen_string_literal: true RSpec.describe TTY::Which, '#search_paths' do it "defauls search paths" do allow(ENV).to receive(:[]).with('PATH').and_return([]) allow(Dir).to receive(:exist?).and_return(true) expect(TTY::Which.search_paths).to eq([ '/usr/local/bin', '/usr/ucb', '/usr/bin', '/bin']) end it "finds paths in path environment" do paths = ['/bin', '/usr/bin', '/usr/local/bin', '/opt/local/bin'] path = paths.join(::File::PATH_SEPARATOR) allow(ENV).to receive(:[]).with('PATH').and_return(path) allow(Dir).to receive(:exist?).and_return(true) expect(TTY::Which.search_paths).to eq(paths) end it "accepts paths to search as an argument" do paths = ['/bin', '/usr/bin', '/usr/local/bin', '/opt/local/bin'] path = paths.join(::File::PATH_SEPARATOR) allow(Dir).to receive(:exist?).and_return(true) expect(TTY::Which.search_paths(path)).to eq(paths) end end tty-which-0.4.2/spec/unit/which_spec.rb000066400000000000000000000116501361142137700200170ustar00rootroot00000000000000# frozen_string_literal: true RSpec.describe TTY::Which, '#which' do before { stub_const("Which", described_class) } context "without extension" do let(:path) { "/bin:/usr/bin:/usr/local/bin:/opt/local/bin" } let(:cmds) { %w(/usr/bin/ls /bin/sh /usr/bin/ruby /usr/local/git/bin/git) } before do allow(ENV).to receive(:[]).with('PATHEXT').and_return(nil) allow(ENV).to receive(:[]).with('PATH').and_return(path) stub_const("::File::PATH_SEPARATOR", ':') stub_const("::File::SEPARATOR", '/') allow(Dir).to receive(:exist?) { true } end it "handles path with executable file /bin/sh" do allow(Which).to receive(:file_with_path?) { true } allow(Which).to receive(:executable_file?) { true } expect(Which.which('/bin/sh')).to eq('/bin/sh') end it "fails to find path executable" do allow(Which).to receive(:file_with_path?) { true } allow(Which).to receive(:executable_file?) { false } expect(Which.which('/bin/sh')).to eq(nil) end it "searches executable file git" do dir_path = "/usr/local/bin" cmd = "git" expected_path = "#{dir_path}/#{cmd}" allow(Which).to receive(:file_with_path?) { false } allow(Which).to receive(:file_with_exec_ext?) { false } allow(::File).to receive(:join) allow(::File).to receive(:join).with(dir_path, cmd).and_return(expected_path) allow(Which).to receive(:executable_file?) { false } allow(Which).to receive(:executable_file?).with(expected_path) { true } allow(::File).to receive(:absolute_path).with(expected_path). and_return(expected_path) expect(Which.which(cmd)).to eq(expected_path) end it "allows to search through custom paths" do paths = %w(/usr/local/bin /usr/bin /bin) allow(Which).to receive(:executable_file?).with('/usr/local/bin/ruby') { false } allow(Which).to receive(:executable_file?).with('/usr/bin/ruby') { true } allow(::File).to receive(:absolute_path).with('/usr/bin/ruby').and_return('/usr/bin/ruby') expect(TTY::Which.which('ruby', paths: paths)).to eq('/usr/bin/ruby') end end context "with extension" do let(:path) { "C:\\Program Files\\Git\\bin;" } let(:exts) { ".com;.exe;.bat;.cmd" } before do allow(ENV).to receive(:[]).with('PATHEXT').and_return(exts) allow(ENV).to receive(:[]).with('PATH').and_return(path) stub_const("::File::PATH_SEPARATOR", ';') stub_const("::File::SEPARATOR", '\\') allow(Dir).to receive(:exist?) { true } end it "handles path with executable file C:\\Program Files\\Git\\bin\\git" do allow(Which).to receive(:file_with_path?) { true } allow(Which).to receive(:executable_file?).with(any_args) { false } path_with_exe_file = 'C:\Program Files\Git\bin\git' expected_path = "#{path_with_exe_file}.exe" allow(::File).to receive(:join).with(path_with_exe_file, any_args). and_return(path_with_exe_file) allow(::File).to receive(:join).with(path_with_exe_file, '.exe'). and_return(expected_path) allow(Which).to receive(:executable_file?).with(expected_path) { true } allow(::File).to receive(:absolute_path).and_return(expected_path) expect(Which.which(path_with_exe_file)).to eq(expected_path) end it "searches path for executable git.exe" do dir_path = "C:\\Program Files\\Git\\bin" cmd = 'git.exe' expected_path = "#{dir_path}\\#{cmd}" allow(Which).to receive(:file_with_path?) { false } allow(Which).to receive(:file_with_exec_ext?).with(cmd) { true } allow(::File).to receive(:join).with(dir_path, any_args) allow(::File).to receive(:join).with(dir_path, cmd).and_return(expected_path) allow(Which).to receive(:executable_file?).with(any_args) { false } allow(Which).to receive(:executable_file?).with(expected_path) { true } allow(::File).to receive(:absolute_path).with(expected_path). and_return(expected_path) expect(Which.which(cmd)).to eq(expected_path) expect(::File).to have_received(:absolute_path).with(expected_path) end it "searches path for executable git" do dir_path = "C:\\Program Files\\Git\\bin" cmd = 'git' expected_path = "#{dir_path}\\#{cmd}.exe" allow(Which).to receive(:file_with_path?) { false } allow(Which).to receive(:file_with_exec_ext?).with(cmd) { false } allow(::File).to receive(:join).with(dir_path, any_args) allow(::File).to receive(:join).with(dir_path, "#{cmd}.exe"). and_return(expected_path) allow(Which).to receive(:executable_file?).with(any_args) { false } allow(Which).to receive(:executable_file?).with(expected_path) { true } allow(::File).to receive(:absolute_path).with(expected_path). and_return(expected_path) expect(Which.which(cmd)).to eq(expected_path) expect(::File).to have_received(:absolute_path).with(expected_path) end end end tty-which-0.4.2/tasks/000077500000000000000000000000001361142137700145675ustar00rootroot00000000000000tty-which-0.4.2/tasks/console.rake000066400000000000000000000003321361142137700170730ustar00rootroot00000000000000# encoding: utf-8 desc 'Load gem inside irb console' task :console do require 'irb' require 'irb/completion' require File.join(__FILE__, '../../lib/tty-which') ARGV.clear IRB.start end task c: %w[ console ] tty-which-0.4.2/tasks/coverage.rake000066400000000000000000000003221361142137700172230ustar00rootroot00000000000000# encoding: utf-8 desc 'Measure code coverage' task :coverage do begin original, ENV['COVERAGE'] = ENV['COVERAGE'], 'true' Rake::Task['spec'].invoke ensure ENV['COVERAGE'] = original end end tty-which-0.4.2/tasks/spec.rake000066400000000000000000000012551361142137700163700ustar00rootroot00000000000000# encoding: utf-8 begin require 'rspec/core/rake_task' desc 'Run all specs' RSpec::Core::RakeTask.new(:spec) do |task| task.pattern = 'spec/{unit,integration}{,/*/**}/*_spec.rb' end namespace :spec do desc 'Run unit specs' RSpec::Core::RakeTask.new(:unit) do |task| task.pattern = 'spec/unit{,/*/**}/*_spec.rb' end desc 'Run integration specs' RSpec::Core::RakeTask.new(:integration) do |task| task.pattern = 'spec/integration{,/*/**}/*_spec.rb' end end rescue LoadError %w[spec spec:unit spec:integration].each do |name| task name do $stderr.puts "In order to run #{name}, do `gem install rspec`" end end end tty-which-0.4.2/tty-which.gemspec000066400000000000000000000024251361142137700167320ustar00rootroot00000000000000require_relative "lib/tty/which/version" Gem::Specification.new do |spec| spec.name = "tty-which" spec.version = TTY::Which::VERSION spec.authors = ["Piotr Murach"] spec.email = ["piotr@piotrmurach.com"] spec.summary = %q{Platform independent implementation of Unix which command.} spec.description = %q{Platform independent implementation of Unix which command.} spec.homepage = "https://ttytoolkit.org" spec.license = "MIT" spec.metadata = { "allowed_push_host" => "https://rubygems.org", "bug_tracker_uri" => "https://github.com/piotrmurach/tty-which/issues", "changelog_uri" => "https://github.com/piotrmurach/tty-which/blob/master/CHANGELOG.md", "documentation_uri" => "https://www.rubydoc.info/gems/tty-which", "homepage_uri" => spec.homepage, "source_code_uri" => "https://github.com/piotrmurach/tty-which" } spec.files = Dir["lib/**/*", "README.md", "CHANGELOG.md", "LICENSE.txt"] spec.extra_rdoc_files = ["README.md"] spec.bindir = "exe" spec.require_paths = ["lib"] spec.required_ruby_version = ">= 2.0.0" spec.add_development_dependency "bundler", ">= 1.5.0" spec.add_development_dependency "rspec", "~> 3.1" spec.add_development_dependency "rake" end