Sha256: 0f934ee53cbf46868a845e111bf1caa88072a98d887a65400124c45851dc149b

Contents?: true

Size: 1.12 KB

Versions: 1

Compression:

Stored size: 1.12 KB

Contents

module TestUtil
  class CommandResult < StructX
    member :exception
    member :stdout
    member :stderr

    def success?
      exception.kind_of?(SystemExit) and exception.success?
    end

    def report
      unless success?
        puts "ERROR: %s" % exception.message
        exception.backtrace.each do |line|
          puts "TRACE: %s" % line
        end
        puts stdout.string[0..100] if stdout.string.size > 0
        puts stderr.string[0..100] if stderr.string.size > 0
      end
    end
  end

  module Command
    class << self
      def execute(&b)
        res = CommandResult.new(stdout: StringIO.new("", "w"), stderr: StringIO.new("", "w"))
        $stdout = res.stdout
        $stderr = res.stderr
        begin
          b.call
        rescue Object => e
          res.exception = e
        end
        $stdout = STDOUT
        $stderr = STDERR
        return res
      end

      def succeed(&b)
        res = execute(&b)
        res.report
        res.should.success
        return res
      end

      def fail(&b)
        res = execute(&b)
        res.should.not.success
        return res
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
pione-0.2.2 test/test-util/command.rb