class Omnitest::Shell::ExecutionResult

Stores the result of running a command

Attributes

command[R]

@return [String] the command that was executed

exitstatus[R]

@return [Integer] the exit code of the process

stderr[R]

@return [String] the captured standard error

stdout[R]

@return [String] the captured standard output

Public Class Methods

new(results) click to toggle source

@api private

# File lib/omnitest/shell/execution_result.rb, line 23
def initialize(results)
  @command = results.fetch(:command)
  @exitstatus = results.fetch(:exitstatus)
  # Needs to be UTF-8 to serialize as YAML
  # FIXME: But is serializing to YAML still necessary? Have been using PStore.
  @stdout = results.fetch(:stdout).force_encoding('utf-8')
  @stderr = results.fetch(:stderr).force_encoding('utf-8')
end

Public Instance Methods

error!() click to toggle source

Check if the command succeeded and raises and error if it did not. @raises [ExecutionError] if the command did not succeed

# File lib/omnitest/shell/execution_result.rb, line 39
def error!
  unless successful?
    error = ExecutionError.new "#{command} returned exit code #{exitstatus}"
    error.execution_result = self
    fail error
  end
end
successful?() click to toggle source

@return [Boolean] true if the command succeeded (exit code 0)

# File lib/omnitest/shell/execution_result.rb, line 33
def successful?
  @exitstatus == 0
end
to_s() click to toggle source

@return [String] a textual summary of the results

# File lib/omnitest/shell/execution_result.rb, line 48
def to_s
  ''"
  Execution Result:
    command: #{command}
    exitstatus: #{exitstatus}
    stdout:
  #{stdout}
    stderr:
  #{stderr}
  "''
end