Sha256: 35f133cb3622f3f79313e95f5b96e6a56dbe5b799f481cfa7e58050867746825

Contents?: true

Size: 1.16 KB

Versions: 27

Compression:

Stored size: 1.16 KB

Contents

require File.expand_path("../../../base", __FILE__)

require 'vagrant/util/platform'
require 'vagrant/util/which'

describe Vagrant::Util::Which do
  def tester (file_extension, test_extension, mode, &block)
    # create file in temp directory
    filename = '__vagrant_unit_test__'
    dir = Dir.tmpdir
    file = Pathname(dir) + (filename + file_extension)
    file.open("w") { |f| f.write("#") }
    file.chmod(mode)

    # set the path to the directory where the file is located
    savepath = ENV['PATH']
    ENV['PATH'] = dir.to_s
    block.call filename + test_extension
    ENV['PATH'] = savepath

    file.unlink
  end

  it "should return a path for an executable file" do
    tester '.bat', '.bat', 0755 do |name|
      expect(described_class.which(name)).not_to be_nil
    end
  end

  if Vagrant::Util::Platform.windows?
    it "should return a path for a Windows executable file" do
      tester '.bat', '', 0755 do |name|
        expect(described_class.which(name)).not_to be_nil
      end
    end
  end

  it "should return nil for a non-executable file" do
    tester '.txt', '.txt', 0644 do |name|
      expect(described_class.which(name)).to be_nil
    end
  end
end

Version data entries

27 entries across 24 versions & 5 rubygems

Version Path
vagrant-unbundled-2.0.1.0 test/unit/vagrant/util/which_test.rb
vagrant-aws-mkubenka-0.7.2.pre.22 vendor/bundle/ruby/2.3.0/bundler/gems/vagrant-f3fdbf414272/test/unit/vagrant/util/which_test.rb
vagrant-aws-mkubenka-0.7.2.pre.16 vendor/bundle/ruby/2.3.0/bundler/gems/vagrant-1ee58c40e3f5/test/unit/vagrant/util/which_test.rb
vagrant-unbundled-2.0.0.1 test/unit/vagrant/util/which_test.rb
vagrant-unbundled-1.9.8.1 test/unit/vagrant/util/which_test.rb
vagrant-unbundled-1.9.7.1 test/unit/vagrant/util/which_test.rb
vagrant-aws-mkubenka-0.7.2.pre.14 vendor/bundle/ruby/2.3.0/bundler/gems/vagrant-5333e60e2d38/test/unit/vagrant/util/which_test.rb
vagrant-aws-mkubenka-0.7.2.pre.11 vendor/bundle/ruby/2.3.0/bundler/gems/vagrant-5333e60e2d38/test/unit/vagrant/util/which_test.rb
vagrant-aws-mkubenka-0.7.2.pre.10 vendor/bundle/ruby/2.3.0/bundler/gems/vagrant-5333e60e2d38/test/unit/vagrant/util/which_test.rb
vagrant-aws-mkubenka-0.7.2.pre.9 vendor/bundle/ruby/2.3.0/bundler/gems/vagrant-5333e60e2d38/test/unit/vagrant/util/which_test.rb
vagrant-unbundled-1.9.5.1 test/unit/vagrant/util/which_test.rb
vagrant-unbundled-1.9.1.1 test/unit/vagrant/util/which_test.rb
vagrant-compose-yaml-0.1.3 vendor/bundle/ruby/2.2.0/bundler/gems/vagrant-dbb756c7b6da/test/unit/vagrant/util/which_test.rb
vagrant-compose-yaml-0.1.2 vendor/bundle/ruby/2.2.0/bundler/gems/vagrant-dbb756c7b6da/test/unit/vagrant/util/which_test.rb
vagrant-compose-yaml-0.1.1 vendor/bundle/ruby/2.2.0/bundler/gems/vagrant-dbb756c7b6da/test/unit/vagrant/util/which_test.rb
vagrant-compose-yaml-0.1.0 vendor/bundle/ruby/2.2.0/bundler/gems/vagrant-dbb756c7b6da/test/unit/vagrant/util/which_test.rb
vagrant-unbundled-1.8.5.2 test/unit/vagrant/util/which_test.rb
vagrant-unbundled-1.8.5.1 test/unit/vagrant/util/which_test.rb
vagrant-unbundled-1.8.4.2 test/unit/vagrant/util/which_test.rb
vagrant-unbundled-1.8.4.1 test/unit/vagrant/util/which_test.rb