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-2.2.1 spec/unit/util/commands_spec.rb
r10k-2.2.0 spec/unit/util/commands_spec.rb
r10k-2.1.1 spec/unit/util/commands_spec.rb
r10k-2.1.0 spec/unit/util/commands_spec.rb
r10k-2.0.3 spec/unit/util/commands_spec.rb
r10k-2.0.2 spec/unit/util/commands_spec.rb
r10k-2.0.1 spec/unit/util/commands_spec.rb
r10k-2.0.0 spec/unit/util/commands_spec.rb
r10k-1.5.1 spec/unit/util/commands_spec.rb