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 =
"F"
FAILURE_EMOJI =
""
ERROR_CHAR =
"E"
ERROR_EMOJI =
"💥"

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, #valid?

Constructor Details

#initialize(actual:, error:, expected:, got:, negate:, valid:, 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?

  • valid (Boolean)

    Report if the test was true or false?

  • matcher (Symbol)

    The matcher.

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

    The requirement level.



33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/expresenter/fail.rb', line 33

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

  @actual   = actual
  @error    = error
  @expected = expected
  @got      = got
  @negate   = negate
  @valid    = valid
  @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?

  • valid (Boolean)

    Report if the test was true or false?

  • matcher (Symbol)

    The matcher.

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

    The requirement level.

Raises:

  • (Fail)

    A failed spec exception.



18
19
20
# File 'lib/expresenter/fail.rb', line 18

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.



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

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.



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

def emoji
  if failure?
    FAILURE_EMOJI
  else
    ERROR_EMOJI
  end
end

#failed?Boolean

Did the test fail?

Returns:

  • (Boolean)

    The spec passed or failed?



51
52
53
# File 'lib/expresenter/fail.rb', line 51

def failed?
  true
end

#failure?Boolean

The state of failure.

Returns:

  • (Boolean)

    The test was a failure?



58
59
60
# File 'lib/expresenter/fail.rb', line 58

def failure?
  !error?
end

#info?Boolean

The state of info.

Returns:

  • (Boolean)

    The test was an info?



65
66
67
# File 'lib/expresenter/fail.rb', line 65

def info?
  false
end

#to_symSymbol

Identify the state of the result.

Returns:

  • (Symbol)

    The identifier of the state.



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

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

#warning?Boolean

The state of warning.

Returns:

  • (Boolean)

    The test was a warning?



72
73
74
# File 'lib/expresenter/fail.rb', line 72

def warning?
  false
end