Class: SeeingIsBelieving::Result

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/seeing_is_believing/result.rb

Defined Under Namespace

Classes: RecordedException

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeResult

Returns a new instance of Result.



8
9
10
11
# File 'lib/seeing_is_believing/result.rb', line 8

def initialize
  self.stdout = ''
  self.stderr = ''
end

Instance Attribute Details

#exceptionObject Also known as: has_exception?

Returns the value of attribute exception.



6
7
8
# File 'lib/seeing_is_believing/result.rb', line 6

def exception
  @exception
end

#exitstatusObject

Returns the value of attribute exitstatus.



6
7
8
# File 'lib/seeing_is_believing/result.rb', line 6

def exitstatus
  @exitstatus
end

#filenameObject

Returns the value of attribute filename.



6
7
8
# File 'lib/seeing_is_believing/result.rb', line 6

def filename
  @filename
end

#max_line_capturesObject

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_linesObject

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_versionObject

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_versionObject

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

#stderrObject

Returns the value of attribute stderr.



6
7
8
# File 'lib/seeing_is_believing/result.rb', line 6

def stderr
  @stderr
end

#stdoutObject

Returns the value of attribute stdout.



6
7
8
# File 'lib/seeing_is_believing/result.rb', line 6

def stdout
  @stdout
end

#timeout_secondsObject

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



36
37
38
# File 'lib/seeing_is_believing/result.rb', line 36

def [](line_number, type=:inspect)
  results_for(line_number, type)
end

#as_jsonObject



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/seeing_is_believing/result.rb', line 49

def as_json
  ex = has_exception? && {
    line_number_in_this_file: exception.line_number,
    class_name:               exception.class_name,
    message:                  exception.message,
    backtrace:                exception.backtrace,
  }

  { stdout:     stdout,
    stderr:     stderr,
    exitstatus: exitstatus,
    exception:  ex,
    lines:      each.with_object(Hash.new)
                    .with_index(1) { |(result, hash), line_number| hash[line_number] = result },
  }
end

#each(&block) ⇒ Object



40
41
42
43
# File 'lib/seeing_is_believing/result.rb', line 40

def each(&block)
  return to_enum :each unless block
  (1..num_lines).each { |line_number| block.call self[line_number] }
end

#has_stderr?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/seeing_is_believing/result.rb', line 19

def has_stderr?
  stderr && !stderr.empty?
end

#has_stdout?Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/seeing_is_believing/result.rb', line 15

def has_stdout?
  stdout && !stdout.empty?
end

#record_exception(line_number, exception_class, exception_message, exception_backtrace) ⇒ Object



32
33
34
# File 'lib/seeing_is_believing/result.rb', line 32

def record_exception(line_number, exception_class, exception_message, exception_backtrace)
  self.exception = RecordedException.new line_number, exception_class, exception_message, exception_backtrace
end

#record_result(type, line_number, value) ⇒ Object



27
28
29
30
# File 'lib/seeing_is_believing/result.rb', line 27

def record_result(type, line_number, value)
  results_for(line_number, type) << value
  value
end

#timeout?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/seeing_is_believing/result.rb', line 23

def timeout?
  !!timeout_seconds
end