Transform named tuple match data to array

Trying to keep some of the existing code (and better syntax).
This commit is contained in:
Michael Miller 2019-03-22 10:38:09 -06:00
parent 66bd1555ac
commit 8d3ab0d44c

View file

@ -1,3 +1,7 @@
require "./match_data_labeled_value"
require "./match_data_value"
require "./generic_match-data_value"
module Spectator::Matchers module Spectator::Matchers
# Information regarding a expectation parial and matcher. # Information regarding a expectation parial and matcher.
# `Matcher#match` will return a sub-type of this. # `Matcher#match` will return a sub-type of this.
@ -14,7 +18,22 @@ module Spectator::Matchers
# Information about the match. # Information about the match.
# Returned elments will differ by matcher, # Returned elments will differ by matcher,
# but all will return a set of labeled values. # but all will return a set of labeled values.
abstract def values : Array(MatchDataLabeledValue) def values : Array(MatchDataLabeledValue)
named_tuple.map do |key, value|
if value.is_a?(MatchDataValue)
MatchDataLabeledValue.new(key, value)
else
wrapper = GenericMatchDataValue.new(value)
MatchDataLabeledValue.new(key, wrapper)
end
end
end
# Raw information about the match.
# Sub-types must implement this and return a `NamedTuple`
# containing the match data values.
# This will be transformed and returned by `#values`.
private abstract def named_tuple
# Describes the condition that satisfies the matcher. # Describes the condition that satisfies the matcher.
# This is informational and displayed to the end-user. # This is informational and displayed to the end-user.