lib/spectus/result/pass.rb in spectus-3.0.10 vs lib/spectus/result/pass.rb in spectus-3.1.0

- old
+ new

@@ -1,57 +1,84 @@ # frozen_string_literal: true -require_relative 'base' +require_relative 'common' module Spectus module Result # The class that is responsible for reporting that the expectation is true. class Pass - include Base + include Common - # @!attribute [r] message + alias message to_s + + # Did the test fail? # - # @return [String] The message that describe the state. - attr_reader :message + # @return [Boolean] The spec passed or failed? + def failed? + false + end - # The value of the expectation of the spec. + # Did the test pass? # - # @return [Boolean] The spec was true. - def result? - true + # @return [Boolean] The spec passed or failed? + def passed? + !failed? end - # The state of success. + # The state of failure. # - # @return [Boolean] The test was a success. - def success? - got.equal?(true) + # @return [Boolean] The test was a failure? + def failure? + false end # The state of info. # - # @return [Boolean] The test was an info. + # @return [Boolean] The test was an info? def info? - !success? + !error.nil? end + # The state of warning. + # + # @return [Boolean] The test was a warning? + def warning? + got.equal?(false) + end + # Identify the state of the result. # # @return [Symbol] The identifier of the state. def to_sym - success? ? :success : :info + return :success if success? + return :warning if warning? + + :info 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) + def char if success? - color ? "\e[32m.\e[0m" : '.' + '.' + elsif warning? + 'W' else - color ? "\e[33mI\e[0m" : 'I' + 'I' + end + end + + # Express the result with one emoji. + # + # @return [String] The emoji that identify the result. + def emoji + if success? + '✅' + elsif warning? + '⚠️' + else + '💡' end end end end end