Module: Expresenter::Common

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

Overview

Common collection of methods.

Constant Summary collapse

SPACE =
" "

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.



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

def actual
  @actual
end

#errorException? (readonly)

Returns Any possible raised exception.

Returns:

  • (Exception, nil)

    Any possible raised exception.



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

def error
  @error
end

#expected#object_id (readonly)

Returns The expected value.

Returns:

  • (#object_id)

    The expected value.



15
16
17
# File 'lib/expresenter/common.rb', line 15

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.



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

def got
  @got
end

#level:MUST, ... (readonly)

Returns The requirement level of the expectation.

Returns:

  • (:MUST, :SHOULD, :MAY)

    The requirement level of the expectation.



25
26
27
# File 'lib/expresenter/common.rb', line 25

def level
  @level
end

#matcherSymbol (readonly)

Returns The matcher.

Returns:

  • (Symbol)

    The matcher.



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

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.



102
103
104
# File 'lib/expresenter/common.rb', line 102

def colored_char
  color(char)
end

#colored_stringString

The colored string representation of the result.

Returns:

  • (String)

    A string representing the result.



109
110
111
# File 'lib/expresenter/common.rb', line 109

def colored_string
  color(to_bold_s)
end

#definitionString

The readable definition.

Returns:

  • (String)

    A readable string of the definition.



80
81
82
# File 'lib/expresenter/common.rb', line 80

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

#error?Boolean

The state of error.

Returns:

  • (Boolean)

    The test raised an error?



44
45
46
# File 'lib/expresenter/common.rb', line 44

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.



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

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

#negate?Boolean

The value of the negate instance variable.

Returns:

  • (Boolean)

    Evaluated to a negative assertion?



37
38
39
# File 'lib/expresenter/common.rb', line 37

def negate?
  @negate
end

#passed?Boolean

Did the test pass?

Returns:

  • (Boolean)

    The spec passed or failed?



30
31
32
# File 'lib/expresenter/common.rb', line 30

def passed?
  !failed?
end

#success?Boolean

The state of success.

Returns:

  • (Boolean)

    The test was a success?



51
52
53
# File 'lib/expresenter/common.rb', line 51

def success?
  got.equal?(true)
end

#summaryString

The summary of the result.

Returns:

  • (String)

    A string representing the summary of the result.



87
88
89
90
91
92
93
94
95
96
97
# File 'lib/expresenter/common.rb', line 87

def summary
  if error?
    error.message
  elsif actual.is_a?(::Exception)
    actual.message
  elsif actual == expected
    ["expected", negation, "to", definition].compact.join(SPACE)
  else
    ["expected", actual.inspect, negation, "to", definition].compact.join(SPACE)
  end
end

#titreString

Titre for the result.

Returns:

  • (String)

    A string representing the titre.



123
124
125
126
127
128
129
# File 'lib/expresenter/common.rb', line 123

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.



116
117
118
# File 'lib/expresenter/common.rb', line 116

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?



59
60
61
# File 'lib/expresenter/common.rb', line 59

def valid?
  @valid
end