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.

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, #maybe_negate, #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.



27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/expresenter/fail.rb', line 27

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.



12
13
14
# File 'lib/expresenter/fail.rb', line 12

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.



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

def char
  if failure?
    "F"
  else
    "E"
  end
end

#emojiString

Express the result with one emoji.

Returns:

  • (String)

    The emoji that identify the result.



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

def emoji
  if failure?
    "❌"
  else
    "💥"
  end
end

#failed?Boolean

Did the test fail?

Returns:

  • (Boolean)

    The spec passed or failed?



45
46
47
# File 'lib/expresenter/fail.rb', line 45

def failed?
  true
end

#failure?Boolean

The state of failure.

Returns:

  • (Boolean)

    The test was a failure?



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

def failure?
  !error?
end

#info?Boolean

The state of info.

Returns:

  • (Boolean)

    The test was an info?



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

def info?
  false
end

#to_symSymbol

Identify the state of the result.

Returns:

  • (Symbol)

    The identifier of the state.



73
74
75
76
77
78
79
# File 'lib/expresenter/fail.rb', line 73

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

#warning?Boolean

The state of warning.

Returns:

  • (Boolean)

    The test was a warning?



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

def warning?
  false
end