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