Exception: Expresenter::Fail

Inherits:
StandardError
  • Object
show all
Includes:
Common
Defined in:
lib/expresenter/fail.rb

Overview

The class that is responsible for reporting that an expectation is false.

Constant Summary collapse

FAILURE_CHAR =

Char representing a failure.

"F"
FAILURE_EMOJI =

Emoji representing a failure.

""
ERROR_CHAR =

Char representing an error.

"E"
ERROR_EMOJI =

Emoji representing an error.

"💥"

Constants included from Common

Common::SPACE

Instance Attribute Summary

Attributes included from Common

#actual, #definition, #error, #expected, #got, #level

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Common

#colored_char, #colored_string, #error?, #inspect, #negate?, #passed?, #success?, #summary, #titre, #to_s

Constructor Details

#initialize(actual:, definition:, error:, expected:, got:, negate:, level:) ⇒ Fail

Initialize method.

Parameters:

  • actual (#object_id)

    Returned value by the challenged subject.

  • definition (String)

    A readable string of the matcher and any expected values.

  • error (Exception, nil)

    Any possible raised exception.

  • expected (#object_id)

    The expected value.

  • got (Boolean, nil)

    The result of the boolean comparison between the actual value and the expected value through the matcher.

  • negate (Boolean)

    Evaluated to a negative assertion?

  • level (:MUST, :SHOULD, :MAY)

    The requirement level.



39
40
41
42
43
44
45
46
47
48
49
# 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

Class Method Details

.with(**details) ⇒ Object

Parameters:

  • actual (#object_id)

    Returned value by the challenged subject.

  • definition (String)

    A readable string of the matcher and any expected values.

  • error (Exception, nil)

    Any possible raised exception.

  • expected (#object_id)

    The expected value.

  • got (Boolean, nil)

    The result of the boolean comparison between the actual value and the expected value through the matcher.

  • negate (Boolean)

    Evaluated to a negative assertion?

  • level (:MUST, :SHOULD, :MAY)

    The requirement level.

Raises:

  • (Fail)

    A failed spec exception.



24
25
26
# File 'lib/expresenter/fail.rb', line 24

def self.with(**details)
  raise new(**details)
end

Instance Method Details

#charString

Express the result with one char.

Returns:

  • (String)

    The char that identify the result.



93
94
95
96
97
98
99
# File 'lib/expresenter/fail.rb', line 93

def char
  if failure?
    FAILURE_CHAR
  else
    ERROR_CHAR
  end
end

#emojiString

Express the result with one emoji.

Returns:

  • (String)

    The emoji that identify the result.



104
105
106
107
108
109
110
# File 'lib/expresenter/fail.rb', line 104

def emoji
  if failure?
    FAILURE_EMOJI
  else
    ERROR_EMOJI
  end
end

#failed?Boolean

Did the test fail?

Returns:

  • (Boolean)

    The spec passed or failed?



54
55
56
# File 'lib/expresenter/fail.rb', line 54

def failed?
  true
end

#failure?Boolean

The state of failure.

Returns:

  • (Boolean)

    The test was a failure?



61
62
63
# File 'lib/expresenter/fail.rb', line 61

def failure?
  !error?
end

#info?Boolean

The state of info.

Returns:

  • (Boolean)

    The test was an info?



68
69
70
# File 'lib/expresenter/fail.rb', line 68

def info?
  false
end

#to_symSymbol

Identify the state of the result.

Returns:

  • (Symbol)

    The identifier of the state.



82
83
84
85
86
87
88
# File 'lib/expresenter/fail.rb', line 82

def to_sym
  if failure?
    :failure
  else
    :error
  end
end

#warning?Boolean

The state of warning.

Returns:

  • (Boolean)

    The test was a warning?



75
76
77
# File 'lib/expresenter/fail.rb', line 75

def warning?
  false
end