Sha256: 14a22f997f4bddc912591dea05fe970c894a5310b9dc0239d882951f59928060

Contents?: true

Size: 1.62 KB

Versions: 27

Compression:

Stored size: 1.62 KB

Contents

# encoding: utf-8

require 'fedux_org_stdlib/core_ext/file/which'

RSpec.describe 'File' do
  around :example do |example|
    with_env 'PATH' => absolute_path('.') do
      example.run
    end
  end

  context '#which' do
    it 'returns path to command' do
      touch_file 'vim'
      filesystem_permissions '0755', 'vim'

      expect(File.which('vim')).to eq absolute_path('vim')
    end

    it 'uses a different search path' do
      touch_file 'vim'
      filesystem_permissions '0755', 'vim'
      expect(File.which('vim', absolute_path('.'))).to eq absolute_path('vim')
    end

    it 'returns nil if command could not be found' do
      expect(File.which('vim')).to be nil
    end

    it 'returns nil if command is not executable' do
      touch_file 'vim'
      filesystem_permissions '0644', 'vim'
      expect(File.which('vim')).to be nil
    end

    it 'returns nil if command is not a file' do
      create_dir 'vim'
      expect(File.which('vim')).to be nil
    end

    it 'supports ~' do
      with_env 'HOME' => absolute_path('.') do
        touch_file 'vim'
        filesystem_permissions '0755', 'vim'
        expect(File.which('vim', '~/')).to eq absolute_path('vim')
      end
    end

    it 'returns nil if command path is blank' do
      expect(File.which('')).to eq nil
      expect(File.which(nil)).to eq nil
      expect(File.which([])).to eq nil
    end

    it 'fails if search path is blank' do
      expect { File.which('vim', '') }.to raise_error ArgumentError
      expect { File.which('vim', nil) }.to raise_error ArgumentError
      expect { File.which('vim', []) }.to raise_error ArgumentError
    end
  end
end

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
fedux_org-stdlib-0.11.18 spec/core_ext/file/which.rb
fedux_org-stdlib-0.11.17 spec/core_ext/file/which.rb
fedux_org-stdlib-0.11.16 spec/core_ext/file/which.rb
fedux_org-stdlib-0.11.15 spec/core_ext/file/which.rb
fedux_org-stdlib-0.11.14 spec/core_ext/file/which.rb
fedux_org-stdlib-0.11.12 spec/core_ext/file/which.rb
fedux_org-stdlib-0.11.11 spec/core_ext/file/which.rb
fedux_org-stdlib-0.11.9 spec/core_ext/file/which.rb
fedux_org-stdlib-0.11.8 spec/core_ext/file/which.rb
fedux_org-stdlib-0.11.7 spec/core_ext/file/which.rb
fedux_org-stdlib-0.11.6 spec/core_ext/file/which.rb
fedux_org-stdlib-0.11.5 spec/core_ext/file/which.rb
fedux_org-stdlib-0.11.4 spec/core_ext/file/which.rb
fedux_org-stdlib-0.11.3 spec/core_ext/file/which.rb
fedux_org-stdlib-0.11.2 spec/core_ext/file/which.rb
fedux_org-stdlib-0.11.1 spec/core_ext/file/which.rb
fedux_org-stdlib-0.11.0 spec/core_ext/file/which.rb
fedux_org-stdlib-0.10.9 spec/core_ext/file/which.rb
fedux_org-stdlib-0.10.8 spec/core_ext/file/which.rb
fedux_org-stdlib-0.10.7 spec/core_ext/file/which.rb