Class: Expresenter::Pass

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

Overview

Class responsible for handling and reporting successful test expectations.

The Pass class represents test results that didn’t fail, but can be in different states:

  • Success: Test passed completely as expected

  • Warning: Test passed but with some concerns (typically for :SHOULD or :MAY requirements)

  • Info: Test passed but with additional information to note

Each state has its own character indicator, emoji, and color for easy visual identification in test output:

  • Success: “.” (green) ✅

  • Warning: “W” (yellow) ⚠️

  • Info: “I” (blue) 💡

Examples:

Creating a successful test result

result = Expresenter::Pass.new(
  actual: "foo",
  definition: 'eq "foo"',
  error: nil,
  got: true,
  negate: false,
  level: :MUST
)
result.success?   # => true
result.warning?   # => false
result.info?      # => false
result.to_sym    # => :success
result.char      # => "."
result.emoji     # => "✅"
result.to_s      # => "Success: expected \"foo\" to eq \"foo\"."

Creating a warning result

result = Expresenter::Pass.new(
  actual: "foo",
  definition: 'eq "foo"',
  error: nil,
  got: false,  # Warning state is triggered when got: false
  negate: false,
  level: :SHOULD
)
result.warning?   # => true
result.to_sym    # => :warning
result.char      # => "W"
result.emoji     # => "⚠️"

Constant Summary collapse

INFO_CHAR =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Single character indicator for informational results.

"I"
INFO_EMOJI =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Emoji indicator for informational results.

"💡"
SUCCESS_CHAR =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Single character indicator for successful results.

"."
SUCCESS_EMOJI =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Emoji indicator for successful results.

""
WARNING_CHAR =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Single character indicator for warning results.

"W"
WARNING_EMOJI =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Emoji indicator for warning results.

"⚠️"

Constants included from Common

Common::SPACE

Instance Attribute Summary

Attributes included from Common

#actual, #definition, #error, #got, #level

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Common

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

Constructor Details

#initialize(actual:, definition:, error:, got:, negate:, level:) ⇒ Pass

Initializes a new Pass instance.

Parameters:

  • actual (#object_id)

    The actual value returned by the test

  • definition (String)

    Human-readable description of the expectation

  • error (Exception, nil)

    Any exception that occurred (for info states)

  • got (Boolean, nil)

    Result of comparing actual vs expected values

  • negate (Boolean)

    Whether this is a negative assertion

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

    The requirement level of the test



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

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

Class Method Details

.with(**details) ⇒ Pass

Creates a new Pass instance with the given details.

Examples:

Expresenter::Pass.with(
  actual: "foo",
  definition: 'eq "foo"',
  error: nil,
  got: true,
  negate: false,
  level: :MUST
)

Parameters:

  • details (Hash)

    Test result details (see #initialize for parameters)

Returns:

  • (Pass)

    A new Pass instance



89
90
91
# File 'lib/expresenter/pass.rb', line 89

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

Instance Method Details

#charString

Returns a single character representing the result state.

Returns:

  • (String)

    “.” for success, “W” for warning, “I” for info



156
157
158
159
160
161
162
163
164
# File 'lib/expresenter/pass.rb', line 156

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

#emojiString

Returns an emoji representing the result state.

Returns:

  • (String)

    “✅” for success, “⚠️” for warning, “💡” for info



169
170
171
172
173
174
175
176
177
# File 'lib/expresenter/pass.rb', line 169

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

#failed?false

Always returns false since this class represents passed tests.

Returns:

  • (false)

    Always returns false



115
116
117
# File 'lib/expresenter/pass.rb', line 115

def failed?
  false
end

#failure?false

Pass results are never failures.

Returns:

  • (false)

    Always returns false



122
123
124
# File 'lib/expresenter/pass.rb', line 122

def failure?
  false
end

#info?Boolean

Indicates if this is an informational result.

Returns:

  • (Boolean)

    true if an error was captured but the test still passed



129
130
131
# File 'lib/expresenter/pass.rb', line 129

def info?
  !error.nil?
end

#to_sym:success, ...

Returns the symbolic representation of the result state.

Returns:

  • (:success, :warning, :info)

    The type of pass result



143
144
145
146
147
148
149
150
151
# File 'lib/expresenter/pass.rb', line 143

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

#warning?Boolean

Indicates if this is a warning result.

Returns:

  • (Boolean)

    true if got equals false, indicating a non-critical issue



136
137
138
# File 'lib/expresenter/pass.rb', line 136

def warning?
  got.equal?(false)
end