class Expresenter::Fail
The class that is responsible for reporting that an expectation is false.
Constants
- ERROR_CHAR
Char representing an error.
- ERROR_EMOJI
Emoji representing an error.
- FAILURE_CHAR
Char representing a failure.
- FAILURE_EMOJI
Emoji representing a failure.
Public Class Methods
Initialize method.
@param actual [#object_id] Returned value by the challenged subject. @param definition [String] A readable string of the matcher and any
expected values.
@param error [Exception, nil] Any possible raised exception. @param expected [#object_id] The expected value. @param got [Boolean, nil] The result of the boolean comparison
between the actual value and the expected value through the matcher.
@param negate [Boolean] Evaluated to a negative assertion? @param level [:MUST, :SHOULD, :MAY] The requirement level.
# File lib/expresenter/fail.rb, line 39 def initialize(actual:, definition:, error:, expected:, got:, negate:, level:) @actual = actual @definition = definition @error = error @expected = expected @got = got @negate = negate @level = level super(to_s) end
@param (see Fail#initialize) @raise [Fail] A failed spec exception.
# File lib/expresenter/fail.rb, line 24 def self.with(**details) raise new(**details) end
Public Instance Methods
Express the result with one char.
@return [String] The char that identify the result.
# File lib/expresenter/fail.rb, line 93 def char if failure? FAILURE_CHAR else ERROR_CHAR end end
Express the result with one emoji.
@return [String] The emoji that identify the result.
# File lib/expresenter/fail.rb, line 104 def emoji if failure? FAILURE_EMOJI else ERROR_EMOJI end end
Did the test fail?
@return [Boolean] The spec passed or failed?
# File lib/expresenter/fail.rb, line 54 def failed? true end
The state of failure.
@return [Boolean] The test was a failure?
# File lib/expresenter/fail.rb, line 61 def failure? !error? end
The state of info.
@return [Boolean] The test was an info?
# File lib/expresenter/fail.rb, line 68 def info? false end
Identify the state of the result.
@return [Symbol] The identifier of the state.
# File lib/expresenter/fail.rb, line 82 def to_sym if failure? :failure else :error end end
The state of warning.
@return [Boolean] The test was a warning?
# File lib/expresenter/fail.rb, line 75 def warning? false end
Protected Instance Methods
# File lib/expresenter/fail.rb, line 114 def color(str) if failure? "\e[35m#{str}\e[0m" # purple else "\e[31m#{str}\e[0m" # red end end