Sha256: f87a353221875cade9d67e3ddc3d3d3fa0ca2d7d8b8034fe068a0799cdf91b60

Contents?: true

Size: 1.51 KB

Versions: 7

Compression:

Stored size: 1.51 KB

Contents

# To change this template, choose Tools | Templates
# and open the template in the editor.

$:.unshift File.join(File.dirname(__FILE__),'..','lib')

require 'rubygems'

require 'test/unit'
gem 'shoulda'; require 'shoulda'

require 'buzzcore/shell_extras'

class ShellTest < Test::Unit::TestCase
  should "raise exception on timeout"
  
  should "not raise exception on non-zero return code, fixed in block. Check result contents"
  
  should "return values from succesfult system call" do
    result = POpen4::shell('ls .')
    assert_instance_of Hash, result
    assert_instance_of String, result[:stdout]
    assert_instance_of String, result[:stderr]
    assert result[:stdout].length > 0
    assert_equal(0, result[:exitcode])
  end

  context "fail correctly" do

    should "raise exception on invalid ls" do
      begin
        result = POpen4::shell('ls asdsadasdasdasdasd')
      rescue ::StandardError => e
        assert_instance_of(POpen4::ExecuteError, e)
        assert_equal 1, e.result[:exitcode]
        assert_instance_of String,e.result[:stdout]
        assert_instance_of String,e.result[:stderr]
        return
      end
      flunk 'should have raised an exception'
    end

    should "not raise exception when fixed in block" do
      result = POpen4::shell('ls asdsadasdasdasdasd') do |r|
        r[:exitcode] = 0
      end
      assert_instance_of Hash, result
      assert_instance_of String, result[:stdout]
      assert_instance_of String, result[:stderr]
      assert_equal(0, result[:exitcode])
    end

  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
buzzcore-0.6.6 test/shell_test.rb
buzzcore-0.6.4 test/shell_test.rb
buzzcore-0.6.3 test/shell_test.rb
buzzcore-0.6.2 test/shell_test.rb
buzzcore-0.6.1 test/shell_test.rb
buzzcore-0.5.1 test/shell_test.rb
buzzcore-0.5.0 test/shell_test.rb