Sha256: 9488402d144a9544822b4a201808327341eccdf535a7f09c2a18852ff7aada6b

Contents?: true

Size: 1.7 KB

Versions: 11

Compression:

Stored size: 1.7 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) { lambda { |p| FileUtils.touch(p) }}

  before {
    create_entry.call(executable_path)

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

  after {
    FileUtils.rm_rf(temp_dir)
  }

  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) { lambda { |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) { lambda { |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

11 entries across 11 versions & 1 rubygems

Version Path
rake-funnel-0.3.2.pre spec/rake/funnel/support/which_spec.rb
rake-funnel-0.3.1.pre spec/rake/funnel/support/which_spec.rb
rake-funnel-0.3.0.pre spec/rake/funnel/support/which_spec.rb
rake-funnel-0.2.0.pre spec/rake/funnel/support/which_spec.rb
rake-funnel-0.1.0.pre spec/rake/funnel/support/which_spec.rb
rake-funnel-0.0.6.pre spec/rake/funnel/support/which_spec.rb
rake-funnel-0.0.5.pre spec/rake/funnel/support/which_spec.rb
rake-funnel-0.0.4.pre spec/rake/funnel/support/which_spec.rb
rake-funnel-0.0.3.pre spec/rake/funnel/support/which_spec.rb
rake-funnel-0.0.2.pre spec/rake/funnel/support/which_spec.rb
rake-funnel-0.0.1.pre spec/rake/funnel/support/which_spec.rb