Update EmptyMatcher to use MatchData

This commit is contained in:
Michael Miller 2019-03-03 20:21:39 -07:00
parent be3218bcd8
commit df663d30d9
2 changed files with 90 additions and 48 deletions

View file

@ -11,26 +11,38 @@ 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")
def match(partial)
actual = partial.actual
matched = actual.empty?
MatchData.new(matched, actual, partial.label)
end
# Determines whether the matcher is satisfied with the value given to it.
# True is returned if the match was successful, false otherwise.
def match?(partial)
partial.actual.empty?
end
# Match data specific to this matcher.
private struct MatchData(T) < MatchData
# Creates the match data.
def initialize(matched, @actual : T, @actual_label : String)
super(matched)
end
# Describes the condition that satisfies the matcher.
# This is informational and displayed to the end-user.
def message(partial)
"Expected #{partial.label} to be empty"
end
# Information about the match.
def values
{
expected: [] of Nil,
actual: @actual,
}
end
# Describes the condition that won't satsify the matcher.
# This is informational and displayed to the end-user.
def negated_message(partial)
"Expected #{partial.label} to not be empty"
# Describes the condition that satisfies the matcher.
# This is informational and displayed to the end-user.
def message
"#{@actual_label} is empty"
end
# Describes the condition that won't satsify the matcher.
# This is informational and displayed to the end-user.
def negated_message
"#{@actual_label} is not empty"
end
end
end
end