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

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



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

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

Instance Method Details

#colored_charString

Express the result with one colored char.

Returns:

  • (String)

    The colored char that identify the result.



69
70
71
# File 'lib/expresenter/common.rb', line 69

def colored_char
  color(char)
end

#colored_stringString

The colored string representation of the result.

Returns:

  • (String)

    A string representing the result.



76
77
78
# File 'lib/expresenter/common.rb', line 76

def colored_string
  color(to_bold_s)
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

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



56
57
58
59
60
61
62
63
64
# File 'lib/expresenter/common.rb', line 56

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

#titreString

Titre for the result.

Returns:

  • (String)

    A string representing the titre.



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

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.



83
84
85
# File 'lib/expresenter/common.rb', line 83

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