Class: SeeingIsBelieving::Result
- Inherits:
-
Object
- Object
- SeeingIsBelieving::Result
- Includes:
- Enumerable
- Defined in:
- lib/seeing_is_believing/result.rb
Defined Under Namespace
Classes: RecordedException
Instance Attribute Summary collapse
-
#exceptions ⇒ Object
Returns the value of attribute exceptions.
-
#exitstatus ⇒ Object
Returns the value of attribute exitstatus.
-
#filename ⇒ Object
Returns the value of attribute filename.
-
#max_line_captures ⇒ Object
Returns the value of attribute max_line_captures.
-
#num_lines ⇒ Object
Returns the value of attribute num_lines.
-
#ruby_version ⇒ Object
Returns the value of attribute ruby_version.
-
#sib_version ⇒ Object
Returns the value of attribute sib_version.
-
#stderr ⇒ Object
Returns the value of attribute stderr.
-
#stdout ⇒ Object
Returns the value of attribute stdout.
-
#timeout_seconds ⇒ Object
Returns the value of attribute timeout_seconds.
Instance Method Summary collapse
- #[](line_number, type = :inspect) ⇒ Object
- #as_json ⇒ Object
- #each(&block) ⇒ Object
- #exception ⇒ Object
- #has_exception? ⇒ Boolean
- #has_stderr? ⇒ Boolean
- #has_stdout? ⇒ Boolean
-
#initialize ⇒ Result
constructor
A new instance of Result.
- #record_exception(line_number, exception_class, exception_message, exception_backtrace) ⇒ Object
- #record_result(type, line_number, value) ⇒ Object
- #timeout? ⇒ Boolean
Constructor Details
#initialize ⇒ Result
Returns a new instance of Result.
12 13 14 15 16 |
# File 'lib/seeing_is_believing/result.rb', line 12 def initialize self.stdout = '' self.stderr = '' self.exceptions = [] end |
Instance Attribute Details
#exceptions ⇒ Object
Returns the value of attribute exceptions.
6 7 8 |
# File 'lib/seeing_is_believing/result.rb', line 6 def exceptions @exceptions end |
#exitstatus ⇒ Object
Returns the value of attribute exitstatus.
6 7 8 |
# File 'lib/seeing_is_believing/result.rb', line 6 def exitstatus @exitstatus end |
#filename ⇒ Object
Returns the value of attribute filename.
6 7 8 |
# File 'lib/seeing_is_believing/result.rb', line 6 def filename @filename end |
#max_line_captures ⇒ Object
Returns the value of attribute max_line_captures.
6 7 8 |
# File 'lib/seeing_is_believing/result.rb', line 6 def max_line_captures @max_line_captures end |
#num_lines ⇒ Object
Returns the value of attribute num_lines.
6 7 8 |
# File 'lib/seeing_is_believing/result.rb', line 6 def num_lines @num_lines end |
#ruby_version ⇒ Object
Returns the value of attribute ruby_version.
6 7 8 |
# File 'lib/seeing_is_believing/result.rb', line 6 def ruby_version @ruby_version end |
#sib_version ⇒ Object
Returns the value of attribute sib_version.
6 7 8 |
# File 'lib/seeing_is_believing/result.rb', line 6 def sib_version @sib_version end |
#stderr ⇒ Object
Returns the value of attribute stderr.
6 7 8 |
# File 'lib/seeing_is_believing/result.rb', line 6 def stderr @stderr end |
#stdout ⇒ Object
Returns the value of attribute stdout.
6 7 8 |
# File 'lib/seeing_is_believing/result.rb', line 6 def stdout @stdout end |
#timeout_seconds ⇒ Object
Returns the value of attribute timeout_seconds.
6 7 8 |
# File 'lib/seeing_is_believing/result.rb', line 6 def timeout_seconds @timeout_seconds end |
Instance Method Details
#[](line_number, type = :inspect) ⇒ Object
43 44 45 |
# File 'lib/seeing_is_believing/result.rb', line 43 def [](line_number, type=:inspect) results_for(line_number, type) end |
#as_json ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/seeing_is_believing/result.rb', line 56 def as_json # We have both an exception and a list of exceptions because multiple exceptions # weren't added until #85, and I don't want to break backwards compatibility right now. { stdout: stdout, stderr: stderr, exitstatus: exitstatus, exception: exception_json(exception), exceptions: exceptions.map { |e| exception_json e }, lines: each.with_object(Hash.new) .with_index(1) { |(result, hash), line_number| hash[line_number] = result }, } end |
#each(&block) ⇒ Object
47 48 49 50 |
# File 'lib/seeing_is_believing/result.rb', line 47 def each(&block) return to_enum :each unless block (1..num_lines).each { |line_number| block.call self[line_number] } end |
#exception ⇒ Object
39 40 41 |
# File 'lib/seeing_is_believing/result.rb', line 39 def exception exceptions.first end |
#has_exception? ⇒ Boolean
8 9 10 |
# File 'lib/seeing_is_believing/result.rb', line 8 def has_exception? exceptions.any? end |
#has_stderr? ⇒ Boolean
22 23 24 |
# File 'lib/seeing_is_believing/result.rb', line 22 def has_stderr? stderr && !stderr.empty? end |
#has_stdout? ⇒ Boolean
18 19 20 |
# File 'lib/seeing_is_believing/result.rb', line 18 def has_stdout? stdout && !stdout.empty? end |
#record_exception(line_number, exception_class, exception_message, exception_backtrace) ⇒ Object
35 36 37 |
# File 'lib/seeing_is_believing/result.rb', line 35 def record_exception(line_number, exception_class, , exception_backtrace) self.exceptions << RecordedException.new(line_number, exception_class, , exception_backtrace) end |
#record_result(type, line_number, value) ⇒ Object
30 31 32 33 |
# File 'lib/seeing_is_believing/result.rb', line 30 def record_result(type, line_number, value) results_for(line_number, type) << value value end |
#timeout? ⇒ Boolean
26 27 28 |
# File 'lib/seeing_is_believing/result.rb', line 26 def timeout? !!timeout_seconds end |