Class: Beaker::Result
- Inherits:
-
Object
- Object
- Beaker::Result
- Defined in:
- lib/beaker/result.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#cmd ⇒ Object
Returns the value of attribute cmd.
-
#exit_code ⇒ Object
Returns the value of attribute exit_code.
-
#host ⇒ Object
Returns the value of attribute host.
-
#output ⇒ Object
Returns the value of attribute output.
-
#raw_output ⇒ Object
Returns the value of attribute raw_output.
-
#raw_stderr ⇒ Object
Returns the value of attribute raw_stderr.
-
#raw_stdout ⇒ Object
Returns the value of attribute raw_stdout.
-
#stderr ⇒ Object
Returns the value of attribute stderr.
-
#stdout ⇒ Object
Returns the value of attribute stdout.
Instance Method Summary collapse
- #convert(string) ⇒ Object
- #exit_code_in?(range) ⇒ Boolean
-
#finalize! ⇒ Object
Ruby assumes chunked data (like something it receives from Net::SSH) to be binary (ASCII-8BIT).
- #formatted_output(limit = 10) ⇒ Object
-
#initialize(host, cmd) ⇒ Result
constructor
A new instance of Result.
- #log(logger) ⇒ Object
- #normalize_line_endings(string) ⇒ Object
- #success? ⇒ Boolean
Constructor Details
#initialize(host, cmd) ⇒ Result
Returns a new instance of Result.
5 6 7 8 9 10 11 12 |
# File 'lib/beaker/result.rb', line 5 def initialize(host, cmd) @host = host @cmd = cmd @stdout = '' @stderr = '' @output = '' @exit_code = nil end |
Instance Attribute Details
#cmd ⇒ Object
Returns the value of attribute cmd.
3 4 5 |
# File 'lib/beaker/result.rb', line 3 def cmd @cmd end |
#exit_code ⇒ Object
Returns the value of attribute exit_code.
3 4 5 |
# File 'lib/beaker/result.rb', line 3 def exit_code @exit_code end |
#host ⇒ Object
Returns the value of attribute host.
3 4 5 |
# File 'lib/beaker/result.rb', line 3 def host @host end |
#output ⇒ Object
Returns the value of attribute output.
3 4 5 |
# File 'lib/beaker/result.rb', line 3 def output @output end |
#raw_output ⇒ Object
Returns the value of attribute raw_output.
3 4 5 |
# File 'lib/beaker/result.rb', line 3 def raw_output @raw_output end |
#raw_stderr ⇒ Object
Returns the value of attribute raw_stderr.
3 4 5 |
# File 'lib/beaker/result.rb', line 3 def raw_stderr @raw_stderr end |
#raw_stdout ⇒ Object
Returns the value of attribute raw_stdout.
3 4 5 |
# File 'lib/beaker/result.rb', line 3 def raw_stdout @raw_stdout end |
#stderr ⇒ Object
Returns the value of attribute stderr.
3 4 5 |
# File 'lib/beaker/result.rb', line 3 def stderr @stderr end |
#stdout ⇒ Object
Returns the value of attribute stdout.
3 4 5 |
# File 'lib/beaker/result.rb', line 3 def stdout @stdout end |
Instance Method Details
#convert(string) ⇒ Object
33 34 35 36 37 |
# File 'lib/beaker/result.rb', line 33 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) ⇒ Boolean
47 48 49 |
# File 'lib/beaker/result.rb', line 47 def exit_code_in?(range) range.include?(@exit_code) end |
#finalize! ⇒ Object
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
20 21 22 23 24 25 26 27 |
# File 'lib/beaker/result.rb', line 20 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) ⇒ Object
43 44 45 |
# File 'lib/beaker/result.rb', line 43 def formatted_output(limit=10) @output.split("\n").last(limit).collect {|x| "\t" + x}.join("\n") end |
#log(logger) ⇒ Object
39 40 41 |
# File 'lib/beaker/result.rb', line 39 def log(logger) logger.debug "Exited: #{exit_code}" unless exit_code == 0 or !exit_code end |
#normalize_line_endings(string) ⇒ Object
29 30 31 |
# File 'lib/beaker/result.rb', line 29 def normalize_line_endings string return string.gsub(/\r\n?/, "\n") end |
#success? ⇒ Boolean
51 52 53 |
# File 'lib/beaker/result.rb', line 51 def success? exit_code == 0 end |