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, #error, #expected, #got, #level, #matcher

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Common

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

Constructor Details

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

Initialize method.

Parameters:

  • actual (#object_id)

    Returned value by the challenged subject.

  • 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?

  • matcher (Symbol)

    The matcher.

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

    The requirement level.



38
39
40
41
42
43
44
45
46
47
48
# File 'lib/expresenter/fail.rb', line 38

def initialize(actual:, error:, expected:, got:, negate:, matcher:, level:)
  @actual   = actual
  @error    = error
  @expected = expected
  @got      = got
  @negate   = negate
  @matcher  = matcher
  @level    = level

  super(to_s)
end

Class Method Details

.with(**details) ⇒ Object

Parameters:

  • actual (#object_id)

    Returned value by the challenged subject.

  • 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?

  • matcher (Symbol)

    The matcher.

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



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

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.



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

def emoji
  if failure?
    FAILURE_EMOJI
  else
    ERROR_EMOJI
  end
end

#failed?Boolean

Did the test fail?

Returns:

  • (Boolean)

    The spec passed or failed?



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

def failed?
  true
end

#failure?Boolean

The state of failure.

Returns:

  • (Boolean)

    The test was a failure?



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

def failure?
  !error?
end

#info?Boolean

The state of info.

Returns:

  • (Boolean)

    The test was an info?



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

def info?
  false
end

#to_symSymbol

Identify the state of the result.

Returns:

  • (Symbol)

    The identifier of the state.



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

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

#warning?Boolean

The state of warning.

Returns:

  • (Boolean)

    The test was a warning?



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

def warning?
  false
end