class Beaker::Result

Attributes

cmd[RW]
exit_code[RW]
host[RW]
output[RW]
raw_output[RW]
raw_stderr[RW]
raw_stdout[RW]
stderr[RW]
stdout[RW]

Public Class Methods

new(host, cmd) click to toggle source
# File lib/beaker/result.rb, line 6
def initialize(host, cmd)
  @host       = host
  @cmd        = cmd
  @stdout     = ''
  @stderr     = ''
  @output     = ''
  @exit_code  = nil
end

Public Instance Methods

convert(string) click to toggle source
# File lib/beaker/result.rb, line 34
def convert string
  # Remove invalid and undefined UTF-8 character encodings
  string.to_s.force_encoding('UTF-8')
  string.to_s.chars.select { |i| i.valid_encoding? }.join
end
exit_code_in?(range) click to toggle source
# File lib/beaker/result.rb, line 48
def exit_code_in?(range)
  range.include?(@exit_code)
end
finalize!() click to toggle source

Ruby assumes chunked data (like something it receives from Net::SSH) to be binary (ASCII-8BIT). We need to gather all chunked data and then re-encode it as the default encoding it assumes for external text (ie our test files and the strings they’re trying to match Net::SSH’s output from) This is also the lowest overhead place to normalize line endings, IIRC

# File lib/beaker/result.rb, line 21
def finalize!
  @raw_stdout = @stdout
  @stdout     = normalize_line_endings(convert(@stdout))
  @raw_stderr = @stderr
  @stderr     = normalize_line_endings(convert(@stderr))
  @raw_output = @output
  @output     = normalize_line_endings(convert(@output))
end
formatted_output(limit = 10) click to toggle source
# File lib/beaker/result.rb, line 44
def formatted_output(limit = 10)
  @output.split("\n").last(limit).collect { |x| "\t" + x }.join("\n")
end
log(logger) click to toggle source
# File lib/beaker/result.rb, line 40
def log(logger)
  logger.debug "Exited: #{exit_code}" unless exit_code == 0 or !exit_code
end
normalize_line_endings(string) click to toggle source
# File lib/beaker/result.rb, line 30
def normalize_line_endings string
  return string.gsub(/\r\n?/, "\n")
end
success?() click to toggle source
# File lib/beaker/result.rb, line 52
def success?
  exit_code == 0
end