Fix value negation of attribute matcher

This commit is contained in:
Michael Miller 2019-09-23 20:52:03 -06:00
parent 00d1cd9ea3
commit 3a6fcb9b0d

View file

@ -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