Fix negation case for respond_to matcher

This commit is contained in:
Michael Miller 2020-01-17 22:08:52 -07:00
parent ed48b80d58
commit a2508d5f6b

View file

@ -16,7 +16,7 @@ module Spectator::Matchers
# Actually performs the test against the expression.
def match(actual : TestExpression(T)) : MatchData forall T
snapshot = snapshot_values(actual.value)
if match?(snapshot)
if snapshot.values.all?
SuccessfulMatchData.new(description)
else
FailedMatchData.new(description, "#{actual.label} does not respond to #{label}", **values(snapshot))
@ -27,7 +27,7 @@ module Spectator::Matchers
# A successful match with `#match` should normally fail for this method, and vice-versa.
def negated_match(actual : TestExpression(T)) : MatchData forall T
snapshot = snapshot_values(actual.value)
if match?(snapshot)
if snapshot.values.any?
FailedMatchData.new(description, "#{actual.label} responds to #{label}", **values(snapshot))
else
SuccessfulMatchData.new(description)
@ -46,13 +46,6 @@ module Spectator::Matchers
{% end %}
end
# Checks if all results from the snapshot are satisified.
private def match?(snapshot)
# The snapshot did the hard work.
# Here just check if all values are true.
snapshot.values.all?
end
# Produces the tuple for the failed match data from a snapshot of the results.
private def values(snapshot)
{% begin %}