Sha256: d202374262bdec4b941220b4b1a3dbc2a11ebef6e73c3fb6b5127fd5fc3b1da7

Contents?: true

Size: 1.44 KB

Versions: 1

Compression:

Stored size: 1.44 KB

Contents

# frozen_string_literal: true

require_relative "common"

module Spectus
  module Result
    # The class that is responsible for reporting that the expectation is false.
    class Fail < ::StandardError
      include Common

      # @raise [Fail] A failed spec result.
      def self.call(**details)
        raise new(**details)
      end

      # Did the test fail?
      #
      # @return [Boolean] The spec passed or failed?
      def failed?
        true
      end

      # The state of failure.
      #
      # @return [Boolean] The test was a failure?
      def failure?
        !error?
      end

      # The state of info.
      #
      # @return [Boolean] The test was an info?
      def info?
        false
      end

      # The state of warning.
      #
      # @return [Boolean] The test was a warning?
      def warning?
        false
      end

      # Identify the state of the result.
      #
      # @return [Symbol] The identifier of the state.
      def to_sym
        failure? ? :failure : :error
      end

      # Express the result with one char.
      #
      # @return [String] The char that identify the result.
      def char
        if failure?
          "F"
        else
          "E"
        end
      end

      # Express the result with one emoji.
      #
      # @return [String] The emoji that identify the result.
      def emoji
        if failure?
          "❌"
        else
          "💥"
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
spectus-3.1.4 lib/spectus/result/fail.rb