Sha256: f0e61c11dd4a6499374c72d090a0fbc1caa3fa5c7b194eec1db3fba513c939ed

Contents?: true

Size: 1.4 KB

Versions: 1

Compression:

Stored size: 1.4 KB

Contents

require File.expand_path('../test_helper', __FILE__)

describe HalfShell do
  
  describe '#execute' do
    
    describe 'when raising exception on non-zero status' do
      
      it 'should raise an exception on non-zero status' do
        lambda { HalfShell.execute('(exit 123)') }.must_raise HalfShell::ExecuteError
      end
      
      it 'should read stdout' do
        HalfShell.execute('echo "foo bar"').stdout.chomp.must_equal "foo bar"
      end
      
      it 'should read stderr' do
        HalfShell.execute('echo "foo bar" 1>&2').stderr.chomp.must_equal "foo bar"
      end
      
    end
    
    describe 'when NOT raising exception on non-zero status' do
      
      it 'should return the correct status code' do
        HalfShell.execute('(exit 123)', :raise => false).status.must_equal 123
      end
      
      it 'should read stdout' do
        HalfShell.execute('echo "foo bar"').stdout.chomp.must_equal "foo bar"
      end
      
      it 'should read stderr' do
        HalfShell.execute('echo "foo bar" 1>&2').stderr.chomp.must_equal "foo bar"
      end
      
    end
    
  end
  
  describe '#execute!' do
    
    it 'should return true when command exited with a zero status' do
      HalfShell.execute!('(exit 0)').must_equal true
    end
    
    it 'should return false when command exited with a non-zero status' do
      HalfShell.execute!('(exit 123)').must_equal false
    end
    
  end
  
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
half_shell-0.0.3 test/half_shell_spec.rb