From 69d085625654dd1a774e3ac92093b19a956fbd19 Mon Sep 17 00:00:00 2001 From: Michael Miller Date: Sat, 26 Jan 2019 16:24:17 -0700 Subject: [PATCH] Add nil matcher --- src/spectator/matchers/nil_matcher.cr | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 src/spectator/matchers/nil_matcher.cr diff --git a/src/spectator/matchers/nil_matcher.cr b/src/spectator/matchers/nil_matcher.cr new file mode 100644 index 0000000..7830d6b --- /dev/null +++ b/src/spectator/matchers/nil_matcher.cr @@ -0,0 +1,25 @@ +require "./value_matcher" + +module Spectator::Matchers + # Common matcher that tests whether a value is nil. + # The values are compared with the `#nil?` method. + struct NilMatcher < ConditionMatcher + # 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.nil? + 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