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