Class: Expresenter::Pass

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

Overview

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

Constant Summary collapse

INFO_CHAR =
"I"
INFO_EMOJI =
"💡"
SUCCESS_CHAR =
"."
SUCCESS_EMOJI =
"✅"
WARNING_CHAR =
"W"
WARNING_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:) ⇒ Pass

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.



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

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
end

Class Method Details

.with(**details) ⇒ Pass

Returns A passed spec instance.

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.

Returns:

  • (Pass)

    A passed spec instance.



21
22
23
# File 'lib/expresenter/pass.rb', line 21

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

Instance Method Details

#charString

Express the result with one char.

Returns:

  • (String)

    The char that identify the result.



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

def char
  if success?
    SUCCESS_CHAR
  elsif warning?
    WARNING_CHAR
  else
    INFO_CHAR
  end
end

#emojiString

Express the result with one emoji.

Returns:

  • (String)

    The emoji that identify the result.



108
109
110
111
112
113
114
115
116
# File 'lib/expresenter/pass.rb', line 108

def emoji
  if success?
    SUCCESS_EMOJI
  elsif warning?
    WARNING_EMOJI
  else
    INFO_EMOJI
  end
end

#failed?Boolean

Did the test fail?

Returns:

  • (Boolean)

    The spec passed or failed?



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

def failed?
  false
end

#failure?Boolean

The state of failure.

Returns:

  • (Boolean)

    The test was a failure?



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

def failure?
  false
end

#info?Boolean

The state of info.

Returns:

  • (Boolean)

    The test was an info?



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

def info?
  !error.nil?
end

#to_symSymbol

Identify the state of the result.

Returns:

  • (Symbol)

    The identifier of the state.



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

def to_sym
  if success?
    :success
  elsif warning?
    :warning
  else
    :info
  end
end

#warning?Boolean

The state of warning.

Returns:

  • (Boolean)

    The test was a warning?



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

def warning?
  got.equal?(false)
end