Sha256: e2f19a5d61863eec01b9e910502d855166ae466071113460870c3f5dd815a928

Contents?: true

Size: 1.62 KB

Versions: 10

Compression:

Stored size: 1.62 KB

Contents

require 'tmpdir'

describe Rake::Funnel::Support::Which do
  let(:temp_dir) { Dir.mktmpdir }
  let(:executable_path) { File.join(temp_dir, 'executable.exe') }
  let(:create_entry) { ->(p) { FileUtils.touch(p) } }

  before do
    create_entry.call(executable_path)

    allow(ENV).to receive(:[]).with('PATH').and_return(temp_dir)
  end

  after do
    FileUtils.rm_rf(temp_dir)
  end

  describe 'executable in PATH' do
    context 'found' do
      it 'should yield executable' do
        expect(described_class.which(File.basename(executable_path))).to eq(executable_path)
      end
    end

    context 'not found' do
      it 'should yield nil' do
        expect(described_class.which('does-not-exist.exe')).to be_nil
      end
    end

    context 'found as directory' do
      let(:create_entry) { ->(p) { FileUtils.mkdir_p(p) } }

      it 'should yield nil' do
        expect(described_class.which('executable.exe')).to be_nil
      end
    end
  end

  describe 'executable in current working directory' do
    context 'found' do
      it 'should yield executable' do
        Dir.chdir(temp_dir) do
          expect(described_class.which(File.basename(executable_path))).to eq(File.basename(executable_path))
        end
      end
    end

    context 'not found' do
      it 'should yield nil' do
        Dir.chdir(temp_dir) do
          expect(described_class.which('does-not-exist.exe')).to be_nil
        end
      end
    end

    context 'found as directory' do
      let(:create_entry) { ->(p) { FileUtils.mkdir_p(p) } }

      it 'should yield nil' do
        expect(described_class.which('executable.exe')).to be_nil
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
rake-funnel-0.22.2 spec/rake/funnel/support/which_spec.rb
rake-funnel-0.22.1 spec/rake/funnel/support/which_spec.rb
rake-funnel-0.22.0 spec/rake/funnel/support/which_spec.rb
rake-funnel-0.21.2 spec/rake/funnel/support/which_spec.rb
rake-funnel-0.21.1 spec/rake/funnel/support/which_spec.rb
rake-funnel-0.21.0 spec/rake/funnel/support/which_spec.rb
rake-funnel-0.20.2 spec/rake/funnel/support/which_spec.rb
rake-funnel-0.20.1 spec/rake/funnel/support/which_spec.rb
rake-funnel-0.20.0 spec/rake/funnel/support/which_spec.rb
rake-funnel-0.19.0 spec/rake/funnel/support/which_spec.rb