Class: TestRunner::ExampleResult

Inherits:
Object
  • Object
show all
Defined in:
lib/test-runner/example_result.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(example, elapsed_time, exception = nil) ⇒ ExampleResult

Returns a new instance of ExampleResult.

Parameters:

  • example (Example)
  • elapsed_time (Float)
  • exception (Exception, nil) (defaults to: nil)


15
16
17
18
19
# File 'lib/test-runner/example_result.rb', line 15

def initialize(example, elapsed_time, exception = nil)
  @example = example
  @elapsed_time = elapsed_time
  @exception = exception
end

Instance Attribute Details

#elapsed_timeFloat (readonly)

Returns:

  • (Float)


10
11
12
# File 'lib/test-runner/example_result.rb', line 10

def elapsed_time
  @elapsed_time
end

#exampleExample (readonly)

Returns:



4
5
6
# File 'lib/test-runner/example_result.rb', line 4

def example
  @example
end

#exceptionException (readonly)

Returns:

  • (Exception)


7
8
9
# File 'lib/test-runner/example_result.rb', line 7

def exception
  @exception
end

Instance Method Details

#errorObject



45
46
47
48
49
50
51
52
53
# File 'lib/test-runner/example_result.rb', line 45

def error
  if @example.pending?
    "Example that was pending due to '#{@example.reason}' unexpectedly succeeded"
  elsif @example.skip?
    @example.reason
  else
    @exception.message
  end
end

#failure?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/test-runner/example_result.rb', line 29

def failure?
  !success?
end

#pending?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/test-runner/example_result.rb', line 33

def pending?
  @example.pending?
end

#skip?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/test-runner/example_result.rb', line 37

def skip?
  @example.skip?
end

#success?Boolean

Returns:

  • (Boolean)


21
22
23
24
25
26
27
# File 'lib/test-runner/example_result.rb', line 21

def success?
  if @example.pending?
    !@exception.nil?
  else
    @example.skip? || @exception.nil?
  end
end

#titleObject



41
42
43
# File 'lib/test-runner/example_result.rb', line 41

def title
  example.full_message
end