Sha256: ca2ba18f7c9b0993f0846b42483a831ed4364484771ce4c921fa723d931fa0fc

Contents?: true

Size: 1.63 KB

Versions: 18

Compression:

Stored size: 1.63 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

18 entries across 18 versions & 1 rubygems

Version Path
rake-funnel-0.18.0 spec/rake/funnel/support/which_spec.rb
rake-funnel-0.17.0 spec/rake/funnel/support/which_spec.rb
rake-funnel-0.16.1 spec/rake/funnel/support/which_spec.rb
rake-funnel-0.16.0 spec/rake/funnel/support/which_spec.rb
rake-funnel-0.15.0.pre spec/rake/funnel/support/which_spec.rb
rake-funnel-0.14.0.pre spec/rake/funnel/support/which_spec.rb
rake-funnel-0.13.0.pre spec/rake/funnel/support/which_spec.rb
rake-funnel-0.12.0.pre spec/rake/funnel/support/which_spec.rb
rake-funnel-0.11.0.pre spec/rake/funnel/support/which_spec.rb
rake-funnel-0.10.0.pre spec/rake/funnel/support/which_spec.rb
rake-funnel-0.9.1.pre spec/rake/funnel/support/which_spec.rb
rake-funnel-0.9.0.pre spec/rake/funnel/support/which_spec.rb
rake-funnel-0.8.0.pre spec/rake/funnel/support/which_spec.rb
rake-funnel-0.7.0.pre spec/rake/funnel/support/which_spec.rb
rake-funnel-0.6.1.pre spec/rake/funnel/support/which_spec.rb
rake-funnel-0.6.0.pre spec/rake/funnel/support/which_spec.rb
rake-funnel-0.5.0.pre spec/rake/funnel/support/which_spec.rb
rake-funnel-0.4.0.pre spec/rake/funnel/support/which_spec.rb