class Expresenter::Pass

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

Constants

INFO_CHAR

Char representing an info.

INFO_EMOJI

Emoji representing an info.

SUCCESS_CHAR

Char representing a success.

SUCCESS_EMOJI

Emoji representing a success.

WARNING_CHAR

Char representing a warning.

WARNING_EMOJI

Emoji representing a warning.

Public Class Methods

new(actual:, definition:, error:, expected:, got:, negate:, level:) click to toggle source

Initialize method.

@param actual [#object_id] Returned value by the challenged subject. @param definition [String] A readable string of the matcher and any

expected values.

@param error [Exception, nil] Any possible raised exception. @param expected [#object_id] The expected value. @param got [Boolean, nil] The result of the boolean comparison

between the actual value and the expected value through the matcher.

@param negate [Boolean] Evaluated to a negative assertion? @param level [:MUST, :SHOULD, :MAY] The requirement level.

# 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
with(**details) click to toggle source

@param (see Pass#initialize) @return [Pass] A passed spec instance.

# File lib/expresenter/pass.rb, line 30
def self.with(**details)
  new(**details)
end

Public Instance Methods

char() click to toggle source

Express the result with one char.

@return [String] The char that identify the result.

# File lib/expresenter/pass.rb, line 101
def char
  if success?
    SUCCESS_CHAR
  elsif warning?
    WARNING_CHAR
  else
    INFO_CHAR
  end
end
emoji() click to toggle source

Express the result with one emoji.

@return [String] The emoji that identify the result.

# File lib/expresenter/pass.rb, line 114
def emoji
  if success?
    SUCCESS_EMOJI
  elsif warning?
    WARNING_EMOJI
  else
    INFO_EMOJI
  end
end
failed?() click to toggle source

Did the test fail?

@return [Boolean] The spec passed or failed?

# File lib/expresenter/pass.rb, line 60
def failed?
  false
end
failure?() click to toggle source

The state of failure.

@return [Boolean] The test was a failure?

# File lib/expresenter/pass.rb, line 67
def failure?
  false
end
info?() click to toggle source

The state of info.

@return [Boolean] The test was an info?

# File lib/expresenter/pass.rb, line 74
def info?
  !error.nil?
end
to_sym() click to toggle source

Identify the state of the result.

@return [Symbol] The identifier of the state.

# File lib/expresenter/pass.rb, line 88
def to_sym
  if success?
    :success
  elsif warning?
    :warning
  else
    :info
  end
end
warning?() click to toggle source

The state of warning.

@return [Boolean] The test was a warning?

# File lib/expresenter/pass.rb, line 81
def warning?
  got.equal?(false)
end

Protected Instance Methods

color(str) click to toggle source
# File lib/expresenter/pass.rb, line 126
def color(str)
  if success?
    "\e[32m#{str}\e[0m" # green
  elsif warning?
    "\e[33m#{str}\e[0m" # yellow
  else
    "\e[36m#{str}\e[0m" # blue
  end
end