Sha256: 63227fc324614dc43420aba238f82403db1ef08ad847f7620406d07841f8e75e

Contents?: true

Size: 1.62 KB

Versions: 69

Compression:

Stored size: 1.62 KB

Contents

require 'r10k/util/commands'
require 'r10k/util/exec_env'

require 'tmpdir'

describe R10K::Util::Commands do
  describe "#which" do

    before do
      allow(File).to receive(:executable?).and_return false
      allow(File).to receive(:file?).and_return false
    end

    def stub_executable(exe)
      allow(File).to receive(:executable?).with(exe).and_return true
      allow(File).to receive(:file?).with(exe).and_return true
    end

    describe "when ENV['PATHEXT'] is unset" do
      let(:path) { Dir.mktmpdir }

      around(:each) do |example|
        R10K::Util::ExecEnv.withenv('PATHEXT' => nil, 'PATH' => path) do
          example.run
        end
      end

      it "returns the first matching command in PATH" do
        exe = File.join(path, 'git')
        stub_executable(exe)
        expect(described_class.which("git")).to eq exe
      end

      it "returns nil if the command could not be found" do
        exe = File.join(path, 'git')
        expect(described_class.which("git")).to be_nil
      end
    end

    describe "when ENV['PATHEXT'] is set" do
      let(:path) { Dir.mktmpdir }

      around(:each) do |example|
        R10K::Util::ExecEnv.withenv('PATHEXT' => '.bat;.exe;.cmd', 'PATH' => path) do
          example.run
        end
      end

      it "returns the first matching command in PATH" do
        exe = File.join(path, 'git.exe')
        stub_executable(exe)
        expect(described_class.which("git")).to eq exe
      end

      it "returns nil if the command could not be found" do
        exe = File.join(path, 'git.exe')
        expect(described_class.which("git")).to be_nil
      end
    end
  end
end

Version data entries

69 entries across 69 versions & 2 rubygems

Version Path
r10k-3.15.0 spec/unit/util/commands_spec.rb
akerl-r10k-3.14.2.1 spec/unit/util/commands_spec.rb
r10k-3.14.2 spec/unit/util/commands_spec.rb
r10k-3.14.1 spec/unit/util/commands_spec.rb
r10k-3.14.0 spec/unit/util/commands_spec.rb
r10k-3.13.0 spec/unit/util/commands_spec.rb
r10k-3.12.1 spec/unit/util/commands_spec.rb
r10k-3.12.0 spec/unit/util/commands_spec.rb
r10k-3.11.0 spec/unit/util/commands_spec.rb
r10k-3.10.0 spec/unit/util/commands_spec.rb
r10k-3.9.3 spec/unit/util/commands_spec.rb
r10k-3.9.2 spec/unit/util/commands_spec.rb
r10k-3.9.1 spec/unit/util/commands_spec.rb
r10k-3.9.0 spec/unit/util/commands_spec.rb
r10k-3.8.0 spec/unit/util/commands_spec.rb
r10k-3.7.0 spec/unit/util/commands_spec.rb
r10k-3.6.0 spec/unit/util/commands_spec.rb
r10k-2.6.9 spec/unit/util/commands_spec.rb
r10k-3.5.2 spec/unit/util/commands_spec.rb
r10k-3.5.1 spec/unit/util/commands_spec.rb