Class: Spectus::Report Private

Inherits:
Object
  • Object
show all
Defined in:
lib/spectus/report.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

The class that is responsible for reporting the result of the test.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(matcher, negate, state, result) ⇒ Report

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Initialize the report class.

Parameters:

  • matcher (#matches?)

    The matcher.

  • negate (Boolean)

    Evaluate to a negative assertion.

  • state (Sandbox)

    The sandbox that tested the code.

  • result (Boolean)

    The result of the test.



15
16
17
18
19
20
# File 'lib/spectus/report.rb', line 15

def initialize(matcher, negate, state, result)
  @matcher = matcher
  @negate  = negate
  @state   = state
  @result  = result
end

Instance Attribute Details

#matcher#matches? (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns The matcher.

Returns:

  • (#matches?)

    The matcher.



25
26
27
# File 'lib/spectus/report.rb', line 25

def matcher
  @matcher
end

#resultBoolean (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns The result of the test.

Returns:

  • (Boolean)

    The result of the test.



42
43
44
# File 'lib/spectus/report.rb', line 42

def result
  @result
end

#stateSandbox (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns The sandbox that tested the code.

Returns:

  • (Sandbox)

    The sandbox that tested the code.



37
38
39
# File 'lib/spectus/report.rb', line 37

def state
  @state
end

Instance Method Details

#definitionString

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

The readable definition.

Returns:

  • (String)

    The readable definition string.



88
89
90
# File 'lib/spectus/report.rb', line 88

def definition
  matcher.to_s
end

#maybe_exceptionString

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

The type of exception, if any.

Returns:

  • (String)

    The type of exception, or an empty string.



81
82
83
# File 'lib/spectus/report.rb', line 81

def maybe_exception
  state.exception.nil? ? '' : " (#{state.exception.class})"
end

#maybe_negateString

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

The negation, if any.

Returns:

  • (String)

    The negation, or an empty string.



74
75
76
# File 'lib/spectus/report.rb', line 74

def maybe_negate
  negate? ? ' not' : ''
end

#negate?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

The value of the negate instance variable.

Returns:

  • (Boolean)

    Evaluated to a negative assertion or not.



30
31
32
# File 'lib/spectus/report.rb', line 30

def negate?
  @negate
end

#summaryString

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

The summary of the state.

Returns:

  • (String)

    The summary of the state.



65
66
67
68
69
# File 'lib/spectus/report.rb', line 65

def summary
  return state.exception.message unless state.valid? || state.exception.nil?

  "Expected #{state.actual.inspect}#{maybe_negate} to #{definition}"
end

#titleString

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

The title of the state.

Returns:

  • (String)

    The title of the state.



54
55
56
57
58
59
60
# File 'lib/spectus/report.rb', line 54

def title
  if result
    state.got ? 'Pass' : 'Info'
  else
    state.exception.nil? ? 'Failure' : 'Error'
  end
end

#to_sString

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

The message.

Returns:

  • (String)

    The message that describe the state.



47
48
49
# File 'lib/spectus/report.rb', line 47

def to_s
  "#{title}: #{summary}#{maybe_exception}."
end