Exception: Expresenter::Fail
- Inherits:
-
StandardError
- Object
- StandardError
- Expresenter::Fail
- Includes:
- Common
- Defined in:
- lib/expresenter/fail.rb
Overview
Class responsible for handling and reporting failed test expectations.
The Fail class represents test failures and errors, inheriting from StandardError to support exception handling. It distinguishes between two types of failures:
-
Regular failures: When an assertion fails but no exception occurred
-
Errors: When an unexpected exception was raised during the test
Constant Summary collapse
- FAILURE_CHAR =
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.
Single character indicator for test failures.
"F"
- FAILURE_EMOJI =
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.
Emoji indicator for test failures.
"ā"
- ERROR_CHAR =
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.
Single character indicator for test errors.
"E"
- ERROR_EMOJI =
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.
Emoji indicator for test errors.
"š„"
Constants included from Common
Instance Attribute Summary
Attributes included from Common
#actual, #definition, #error, #got, #level
Class Method Summary collapse
-
.with(**details) ⇒ Object
Creates and raises a new Fail instance with the given details.
Instance Method Summary collapse
-
#char ⇒ String
Returns a single character representing the failure type.
-
#emoji ⇒ String
Returns an emoji representing the failure type.
-
#failed? ⇒ true
Always returns true since this class represents failed tests.
-
#failure? ⇒ Boolean
Indicates if this is a regular failure (not an error).
-
#info? ⇒ false
Fail results are never informational.
-
#initialize(actual:, definition:, error:, got:, negate:, level:) ⇒ Fail
constructor
Initializes a new Fail instance.
-
#to_sym ⇒ :failure, :error
Returns the symbolic representation of the failure type.
-
#warning? ⇒ false
Fail results are never warnings.
Methods included from Common
#colored_char, #colored_string, #error?, #negate?, #passed?, #success?, #summary, #titre, #to_s
Constructor Details
#initialize(actual:, definition:, error:, got:, negate:, level:) ⇒ Fail
Initializes a new Fail instance.
105 106 107 108 109 110 111 112 113 114 |
# File 'lib/expresenter/fail.rb', line 105 def initialize(actual:, definition:, error:, got:, negate:, level:) @actual = actual @definition = definition @error = error @got = got @negate = negate @level = level super(to_s) end |
Class Method Details
.with(**details) ⇒ Object
Creates and raises a new Fail instance with the given details.
83 84 85 |
# File 'lib/expresenter/fail.rb', line 83 def self.with(**details) raise new(**details) end |
Instance Method Details
#char ⇒ String
Returns a single character representing the failure type.
158 159 160 161 162 163 164 |
# File 'lib/expresenter/fail.rb', line 158 def char if failure? FAILURE_CHAR else ERROR_CHAR end end |
#emoji ⇒ String
Returns an emoji representing the failure type.
169 170 171 172 173 174 175 |
# File 'lib/expresenter/fail.rb', line 169 def emoji if failure? FAILURE_EMOJI else ERROR_EMOJI end end |
#failed? ⇒ true
Always returns true since this class represents failed tests.
119 120 121 |
# File 'lib/expresenter/fail.rb', line 119 def failed? true end |
#failure? ⇒ Boolean
Indicates if this is a regular failure (not an error).
126 127 128 |
# File 'lib/expresenter/fail.rb', line 126 def failure? !error? end |
#info? ⇒ false
Fail results are never informational.
133 134 135 |
# File 'lib/expresenter/fail.rb', line 133 def info? false end |
#to_sym ⇒ :failure, :error
Returns the symbolic representation of the failure type.
147 148 149 150 151 152 153 |
# File 'lib/expresenter/fail.rb', line 147 def to_sym if failure? :failure else :error end end |
#warning? ⇒ false
Fail results are never warnings.
140 141 142 |
# File 'lib/expresenter/fail.rb', line 140 def warning? false end |