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 =

Char representing an info.

"I"
INFO_EMOJI =

Emoji representing an info.

"💡"
SUCCESS_CHAR =

Char representing a success.

"."
SUCCESS_EMOJI =

Emoji representing a success.

""
WARNING_CHAR =

Char representing a warning.

"W"
WARNING_EMOJI =

Emoji representing a warning.

"⚠️"

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:) ⇒ Pass

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.



47
48
49
50
51
52
53
54
55
# File 'lib/expresenter/pass.rb', line 47

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

Class Method Details

.with(**details) ⇒ Pass

Returns A passed spec instance.

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.

Returns:

  • (Pass)

    A passed spec instance.



30
31
32
# File 'lib/expresenter/pass.rb', line 30

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.



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

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.



114
115
116
117
118
119
120
121
122
# File 'lib/expresenter/pass.rb', line 114

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?



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

def failed?
  false
end

#failure?Boolean

The state of failure.

Returns:

  • (Boolean)

    The test was a failure?



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

def failure?
  false
end

#info?Boolean

The state of info.

Returns:

  • (Boolean)

    The test was an info?



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

def info?
  !error.nil?
end

#to_symSymbol

Identify the state of the result.

Returns:

  • (Symbol)

    The identifier of the state.



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

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?



81
82
83
# File 'lib/expresenter/pass.rb', line 81

def warning?
  got.equal?(false)
end