Sha256: 4a57865d317274359394ba878866a0733341e71432e11ec78bb628e6f38b5ef3

Contents?: true

Size: 1.67 KB

Versions: 2

Compression:

Stored size: 1.67 KB

Contents

require 'spec_helper'

describe Command do
  context '#run_command' do
    klass = Class.new do
      include Command
    end

    it 'captures stdout' do
      result = klass.new.run_command( 'echo hello_world' )

      expect( result.stdout.chomp ).to eq( 'hello_world' )
    end

    it 'captures stderr' do
      result = klass.new.run_command( 'echo hello_world >&2' )

      expect( result.stderr.chomp ).to eq( 'hello_world' )
    end

    it 'captures exit status' do
      result = klass.new.run_command( 'echo hello_world >&2' )

      expect( result.status.exitstatus ).to eq( 0 )
    end
  end

  context '#which', :focus do
    klass = Class.new do
      include Command
    end

    it 'returns full path for a valid command' do
      expect( klass.new.which( 'which' ) ).to eq( '/usr/bin/which' )
    end

    it 'returns full path for a valid command although a full path is given' do
      expect( klass.new.which( '/usr/bin/which' ) ).to eq( '/usr/bin/which' )
    end

    it 'returns nil if no executable can be found in path' do
      expect( klass.new.which( 'asdfasdf' ) ).to eq( nil )
    end

    it 'uses paths string to search for command' do
      expect( klass.new.which( 'which', '/usr/bin' ) ).to eq( '/usr/bin/which' )
    end

    it 'uses paths array to search for command' do
      expect( klass.new.which( 'which', [ '/usr/bin' ] ) ).to eq( '/usr/bin/which' )
    end

    it 'uses pathexts to search for command' do
      expect( klass.new.which( 'which', [ '/usr/bin' ], '' ) ).to eq( '/usr/bin/which' )
    end

    it 'uses pathexts array to search for command' do
      expect( klass.new.which( 'which', [ '/usr/bin' ], [ '' ]) ).to eq( '/usr/bin/which' )
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
fedux_org-stdlib-0.1.3 spec/command_spec.rb
fedux_org-stdlib-0.1.2 spec/command_spec.rb