Module: Expresenter::Common

Included in:
Fail, Pass
Defined in:
lib/expresenter/common.rb

Overview

Common collection of methods.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#actual#object_id (readonly)

Returned value by the challenged subject.

Returns:

  • (#object_id)

    Returned value by the challenged subject.



7
8
9
# File 'lib/expresenter/common.rb', line 7

def actual
  @actual
end

#errorException? (readonly)

Returns Any possible raised exception.

Returns:

  • (Exception, nil)

    Any possible raised exception.



10
11
12
# File 'lib/expresenter/common.rb', line 10

def error
  @error
end

#expected#object_id (readonly)

Returns The expected value.

Returns:

  • (#object_id)

    The expected value.



13
14
15
# File 'lib/expresenter/common.rb', line 13

def expected
  @expected
end

#got#object_id (readonly)

Returns The result of the boolean comparison between the actual value and the expected value through the matcher.

Returns:

  • (#object_id)

    The result of the boolean comparison between the actual value and the expected value through the matcher.



17
18
19
# File 'lib/expresenter/common.rb', line 17

def got
  @got
end

#level:MUST, ... (readonly)

Returns The requirement level of the expectation.

Returns:

  • (:MUST, :SHOULD, :MAY)

    The requirement level of the expectation.



23
24
25
# File 'lib/expresenter/common.rb', line 23

def level
  @level
end

#matcher#object_id (readonly)

Returns The matcher.

Returns:

  • (#object_id)

    The matcher.



20
21
22
# File 'lib/expresenter/common.rb', line 20

def matcher
  @matcher
end

Instance Method Details

#colored_charString

Express the result with one colored char.

Returns:

  • (String)

    The colored char that identify the result.



107
108
109
# File 'lib/expresenter/common.rb', line 107

def colored_char
  color(char)
end

#colored_stringString

The colored string representation of the result.

Returns:

  • (String)

    A string representing the result.



114
115
116
# File 'lib/expresenter/common.rb', line 114

def colored_string
  color(to_s)
end

#definitionString

The readable definition.

Returns:

  • (String)

    A readable string of the definition.



78
79
80
# File 'lib/expresenter/common.rb', line 78

def definition
  [matcher, expected&.inspect].compact.join(" ")
end

#error?Boolean

The state of error.

Returns:

  • (Boolean)

    The test raised an error?



42
43
44
# File 'lib/expresenter/common.rb', line 42

def error?
  !error.nil?
end

#inspectString

A string containing a human-readable representation of the result.

Returns:

  • (String)

    The human-readable representation of the result.



64
65
66
67
68
69
70
71
72
73
# File 'lib/expresenter/common.rb', line 64

def inspect
  "#{self.class}(actual: #{actual.inspect}, "     \
                "error: #{error.inspect}, "       \
                "expected: #{expected.inspect}, " \
                "got: #{got.inspect}, "           \
                "matcher: #{matcher.inspect}, "   \
                "negate: #{negate?.inspect}, "    \
                "level: #{level.inspect}, "       \
                "valid: #{valid?.inspect})"       \
end

#maybe_negateString

The negation, if any.

Returns:

  • (String)

    The negation, or an empty string.



85
86
87
# File 'lib/expresenter/common.rb', line 85

def maybe_negate
  negate? ? " not" : ""
end

#negate?Boolean

The value of the negate instance variable.

Returns:

  • (Boolean)

    Evaluated to a negative assertion?



35
36
37
# File 'lib/expresenter/common.rb', line 35

def negate?
  @negate
end

#passed?Boolean

Did the test pass?

Returns:

  • (Boolean)

    The spec passed or failed?



28
29
30
# File 'lib/expresenter/common.rb', line 28

def passed?
  !failed?
end

#success?Boolean

The state of success.

Returns:

  • (Boolean)

    The test was a success?



49
50
51
# File 'lib/expresenter/common.rb', line 49

def success?
  got.equal?(true)
end

#summaryString

The summary of the result.

Returns:

  • (String)

    A string representing the summary of the result.



92
93
94
95
96
97
98
99
100
101
102
# File 'lib/expresenter/common.rb', line 92

def summary
  if error?
    error.message
  elsif actual.is_a?(::Exception)
    actual.message
  elsif actual == expected
    "expected#{maybe_negate} to #{definition}"
  else
    "expected #{actual.inspect}#{maybe_negate} to #{definition}"
  end
end

#titreString

Titre for the result.

Returns:

  • (String)

    A string representing the titre.



128
129
130
131
132
133
134
# File 'lib/expresenter/common.rb', line 128

def titre
  if error?
    error.class.name
  else
    to_sym.to_s.capitalize
  end
end

#to_sString

The representation of the result.

Returns:

  • (String)

    A string representing the result.



121
122
123
# File 'lib/expresenter/common.rb', line 121

def to_s
  "#{titre}: #{summary}."
end

#valid?Boolean

The value of the boolean comparison between the actual value and the expected value.

Returns:

  • (Boolean)

    The test was true or false?



57
58
59
# File 'lib/expresenter/common.rb', line 57

def valid?
  @valid
end