Module: Expresenter::Common
Overview
Common collection of methods shared between Pass and Fail result classes.
This module provides the core functionality for presenting test results, including:
-
Access to test result data (actual value, definition, error state)
-
Test state queries (passed?, error?, success?)
-
Result formatting and presentation (summary, colored output)
-
Support for requirement levels (MUST/SHOULD/MAY)
Constant Summary collapse
- SPACE =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
String constant used for joining message parts.
" "
Instance Attribute Summary collapse
-
#actual ⇒ #object_id
readonly
The actual value returned by the test subject.
-
#definition ⇒ String
readonly
The human-readable description of the expectation.
-
#error ⇒ Exception?
readonly
Any exception that was raised during the test.
-
#got ⇒ #object_id
readonly
The boolean result of comparing the actual value against the expectation.
-
#level ⇒ :MUST, ...
readonly
The requirement level of the expectation.
Instance Method Summary collapse
-
#colored_char ⇒ String
Returns the result indicator with ANSI color codes.
-
#colored_string ⇒ String
Returns the full result message with ANSI color codes.
-
#error? ⇒ Boolean
Checks if an error occurred during the test.
-
#negate? ⇒ Boolean
Checks if this is a negative assertion.
-
#passed? ⇒ Boolean
Checks if the test passed.
-
#success? ⇒ Boolean
Checks if the test was successful.
-
#summary ⇒ String
Generates a human-readable summary of the test result.
-
#titre ⇒ String
Returns the title for the result type.
-
#to_s ⇒ String
Returns the complete result message.
Instance Attribute Details
#actual ⇒ #object_id (readonly)
The actual value returned by the test subject.
38 39 40 |
# File 'lib/expresenter/common.rb', line 38 def actual @actual end |
#definition ⇒ String (readonly)
The human-readable description of the expectation.
45 46 47 |
# File 'lib/expresenter/common.rb', line 45 def definition @definition end |
#error ⇒ Exception? (readonly)
Any exception that was raised during the test.
57 58 59 |
# File 'lib/expresenter/common.rb', line 57 def error @error end |
#got ⇒ #object_id (readonly)
The boolean result of comparing the actual value against the expectation.
64 65 66 |
# File 'lib/expresenter/common.rb', line 64 def got @got end |
#level ⇒ :MUST, ... (readonly)
The requirement level of the expectation.
72 73 74 |
# File 'lib/expresenter/common.rb', line 72 def level @level end |
Instance Method Details
#colored_char ⇒ String
Returns the result indicator with ANSI color codes.
139 140 141 |
# File 'lib/expresenter/common.rb', line 139 def colored_char color(char) end |
#colored_string ⇒ String
Returns the full result message with ANSI color codes.
148 149 150 |
# File 'lib/expresenter/common.rb', line 148 def colored_string color(to_bold_s) end |
#error? ⇒ Boolean
Checks if an error occurred during the test.
103 104 105 |
# File 'lib/expresenter/common.rb', line 103 def error? !error.nil? end |
#negate? ⇒ Boolean
Checks if this is a negative assertion.
89 90 91 |
# File 'lib/expresenter/common.rb', line 89 def negate? @negate end |
#passed? ⇒ Boolean
Checks if the test passed.
79 80 81 |
# File 'lib/expresenter/common.rb', line 79 def passed? !failed? end |
#success? ⇒ Boolean
Checks if the test was successful.
113 114 115 |
# File 'lib/expresenter/common.rb', line 113 def success? got.equal?(true) end |
#summary ⇒ String
Generates a human-readable summary of the test result.
124 125 126 127 128 129 130 131 132 |
# File 'lib/expresenter/common.rb', line 124 def summary if error? error. elsif actual.is_a?(::Exception) actual. else ["expected", actual.inspect, negation, "to", definition].compact.join(SPACE) end end |
#titre ⇒ String
Returns the title for the result type.
168 169 170 171 172 173 174 |
# File 'lib/expresenter/common.rb', line 168 def titre if error? error.class.name else to_sym.to_s.capitalize end end |
#to_s ⇒ String
Returns the complete result message.
157 158 159 |
# File 'lib/expresenter/common.rb', line 157 def to_s "#{titre}: #{summary}." end |