Add MatchData for EqualityMatcher

crystal spec runs, but fails for this commit.
This commit is contained in:
Michael Miller 2019-02-28 13:32:38 -07:00
parent 94cbb9860a
commit b4502711cd

View file

@ -13,7 +13,9 @@ module Spectator::Matchers
# Determines whether the matcher is satisfied with the partial given to it.
# `MatchData` is returned that contains information about the match.
def match(partial) : MatchData
raise NotImplementedError.new("#match")
actual = partial.actual
matched = actual == expected
MatchData.new(matched, expected, actual, partial.label, label)
end
# Describes the condition that satisfies the matcher.
@ -27,5 +29,33 @@ module Spectator::Matchers
def negated_message(partial)
"Expected #{partial.label} to not equal #{label} (using ==)"
end
# Match data specific to this matcher.
private struct MatchData(ExpectedType, ActualType) < MatchData
# Creates the match data.
def initialize(matched, @expected : ExpectedType, @actual : ActualType, @expected_label : String, @actual_label : String)
super(matched)
end
# Information about the match.
def values
{
expected: @expected,
actual: @actual,
}
end
# Describes the condition that satisfies the matcher.
# This is informational and displayed to the end-user.
def message
"#{@expected_label} is #{@actual_label} (using ==)"
end
# Describes the condition that won't satsify the matcher.
# This is informational and displayed to the end-user.
def negated_message
"#{@expected_label} is not #{@actual_label} (using ==)"
end
end
end
end