Sha256: ae04e37a56a1a8a598d210ca38258375ab60be5143b5e721764aaa9c8952ed29

Contents?: true

Size: 1.1 KB

Versions: 14

Compression:

Stored size: 1.1 KB

Contents

require_relative 'base'

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

      # The value of the expectation of the spec.
      #
      # @return [Boolean] The spec was false.
      def result?
        false
      end

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

      # The state of error.
      #
      # @return [Boolean] The test was an error.
      def error?
        !failure?
      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.
      #
      # @param color [Boolean] Enable the color.
      #
      # @return [String] The char that identify the result.
      def to_char(color = false)
        if failure?
          color ? "\e[35mF\e[0m" : 'F'
        else
          color ? "\e[31mE\e[0m" : 'E'
        end
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
spectus-3.0.6 lib/spectus/result/fail.rb
spectus-3.0.5 lib/spectus/result/fail.rb
spectus-3.0.4 lib/spectus/result/fail.rb
spectus-3.0.3 lib/spectus/result/fail.rb
spectus-3.0.2 lib/spectus/result/fail.rb
spectus-3.0.1 lib/spectus/result/fail.rb
spectus-3.0.0 lib/spectus/result/fail.rb
spectus-2.10.0 lib/spectus/result/fail.rb
spectus-2.9.2 lib/spectus/result/fail.rb
spectus-2.9.1 lib/spectus/result/fail.rb
spectus-2.9.0 lib/spectus/result/fail.rb
spectus-2.8.0 lib/spectus/result/fail.rb
spectus-2.7.1 lib/spectus/result/fail.rb
spectus-2.7.0 lib/spectus/result/fail.rb