diff --git a/src/spectator/matchers/empty_matcher.cr b/src/spectator/matchers/empty_matcher.cr new file mode 100644 index 0000000..d2f840e --- /dev/null +++ b/src/spectator/matchers/empty_matcher.cr @@ -0,0 +1,30 @@ +require "./value_matcher" + +module Spectator::Matchers + # Matcher that tests whether a collection is empty. + # The values are checked with the `#empty?` method. + struct NilMatcher < ConditionMatcher + # Creates the matcher. + def initialize + super("empty?") + end + + # Determines whether the matcher is satisfied with the value given to it. + # True is returned if the match was successful, false otherwise. + def match?(partial : Expectations::ValueExpectationPartial(ActualType)) : Bool forall ActualType + partial.actual.empty? + end + + # Describes the condition that satisfies the matcher. + # This is informational and displayed to the end-user. + def message(partial : Expectations::ValueExpectationPartial(ActualType)) : String forall ActualType + "Expected #{partial.label} to be nil" + end + + # Describes the condition that won't satsify the matcher. + # This is informational and displayed to the end-user. + def negated_message(partial : Expectations::ValueExpectationPartial(ActualType)) : String forall ActualType + "Expected #{partial.label} to not be nil" + end + end +end