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.



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

#exceptionsObject

Returns the value of attribute exceptions.



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

def exceptions
  @exceptions
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



43
44
45
# File 'lib/seeing_is_believing/result.rb', line 43

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

#as_jsonObject



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

#exceptionObject



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

def exception
  exceptions.first
end

#has_exception?Boolean

Returns:

  • (Boolean)


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

def has_exception?
  exceptions.any?
end

#has_stderr?Boolean

Returns:

  • (Boolean)


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

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

#has_stdout?Boolean

Returns:

  • (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_message, exception_backtrace)
  self.exceptions << RecordedException.new(line_number, exception_class, exception_message, 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

Returns:

  • (Boolean)


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

def timeout?
  !!timeout_seconds
end