diff --git a/src/spectator/matchers/match_data.cr b/src/spectator/matchers/match_data.cr index 56f1888..8e80276 100644 --- a/src/spectator/matchers/match_data.cr +++ b/src/spectator/matchers/match_data.cr @@ -1,3 +1,7 @@ +require "./match_data_labeled_value" +require "./match_data_value" +require "./generic_match-data_value" + module Spectator::Matchers # Information regarding a expectation parial and matcher. # `Matcher#match` will return a sub-type of this. @@ -14,7 +18,22 @@ module Spectator::Matchers # Information about the match. # Returned elments will differ by matcher, # 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. # This is informational and displayed to the end-user.