Module: Expresenter::Common

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

Overview

Common collection of methods.

Constant Summary collapse

SPACE =

White 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.



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

def actual
  @actual
end

#definitionString (readonly)

Returns A readable string of the matcher and any expected values.

Returns:

  • (String)

    A readable string of the matcher and any expected values.



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

def definition
  @definition
end

#errorException? (readonly)

Returns Any possible raised exception.

Returns:

  • (Exception, nil)

    Any possible raised exception.



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

def error
  @error
end

#expected#object_id (readonly)

Returns The expected value.

Returns:

  • (#object_id)

    The expected value.



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

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.



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

def got
  @got
end

#level:MUST, ... (readonly)

Returns The requirement level of the expectation.

Returns:

  • (:MUST, :SHOULD, :MAY)

    The requirement level of the expectation.



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

def level
  @level
end

Instance Method Details

#colored_charString

Express the result with one colored char.

Returns:

  • (String)

    The colored char that identify the result.



87
88
89
# File 'lib/expresenter/common.rb', line 87

def colored_char
  color(char)
end

#colored_stringString

The colored string representation of the result.

Returns:

  • (String)

    A string representing the result.



94
95
96
# File 'lib/expresenter/common.rb', line 94

def colored_string
  color(to_bold_s)
end

#error?Boolean

The state of error.

Returns:

  • (Boolean)

    The test raised an error?



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

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.



59
60
61
62
63
64
65
66
67
# File 'lib/expresenter/common.rb', line 59

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

#negate?Boolean

The value of the negate instance variable.

Returns:

  • (Boolean)

    Evaluated to a negative assertion?



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

def negate?
  @negate
end

#passed?Boolean

Did the test pass?

Returns:

  • (Boolean)

    The spec passed or failed?



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

def passed?
  !failed?
end

#success?Boolean

The state of success.

Returns:

  • (Boolean)

    The test was a success?



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

def success?
  got.equal?(true)
end

#summaryString

The summary of the result.

Returns:

  • (String)

    A string representing the summary of the result.



72
73
74
75
76
77
78
79
80
81
82
# File 'lib/expresenter/common.rb', line 72

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.



108
109
110
111
112
113
114
# File 'lib/expresenter/common.rb', line 108

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.



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

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