From 3a6fcb9b0d75394226360f4bafbe928a49d660dd Mon Sep 17 00:00:00 2001 From: Michael Miller Date: Mon, 23 Sep 2019 20:52:03 -0600 Subject: [PATCH] Fix value negation of attribute matcher --- src/spectator/matchers/attributes_matcher.cr | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/spectator/matchers/attributes_matcher.cr b/src/spectator/matchers/attributes_matcher.cr index be3e178..93cd62a 100644 --- a/src/spectator/matchers/attributes_matcher.cr +++ b/src/spectator/matchers/attributes_matcher.cr @@ -39,7 +39,7 @@ module Spectator::Matchers def negated_match(actual : TestExpression(T)) : MatchData forall T snapshot = snapshot_values(actual.value) if match?(snapshot) - FailedMatchData.new("#{actual.label} has attributes #{expected.label}", **values(snapshot)) + FailedMatchData.new("#{actual.label} has attributes #{expected.label}", **negated_values(snapshot)) else SuccessfulMatchData.new end @@ -79,5 +79,17 @@ module Spectator::Matchers } {% end %} end + + # Produces the tuple for the failed negated match data from a snapshot of the attributes. + private def negated_values(snapshot) + {% begin %} + { + {% for attribute in ExpectedType.keys %} + {{"expected " + attribute.stringify}}: "Not #{expected.value[{{attribute.symbolize}}].inspect}", + {{"actual " + attribute.stringify}}: snapshot[{{attribute.symbolize}}].inspect, + {% end %} + } + {% end %} + end end end