shard-spectator/spec/helpers/matchers_helper.cr
Michael Miller 5b03ddb7e3 Try different method
This should only have ExceptionMatcher's match data types
2019-03-22 00:37:15 -06:00

26 lines
892 B
Crystal

# Retrieves a value from the `NamedTuple` returned by `Spectator::Matchers::MatchData#values`.
def match_data_value(match_data, key)
match_data.values.fetch(key) { raise "#{key} is missing" }
end
# Retrieves the string representation and base value
# from a `Spectator::Matchers::PrefixedValue`
# in a `NamedTuple` returned by `Spectator::Matchers::MatchData#values`.
def match_data_prefix(match_data, key)
prefix = match_data.values.fetch(key) { raise "#{key} is missing" }
if prefix.responds_to?(:value)
{to_s: prefix.to_s, value: prefix.value}
else
{to_s: prefix.to_s, value: prefix}
end
end
def match_data_prefix2(match_data, key)
puts typeof(match_data.values)
prefix = match_data.values.fetch(key) { raise "#{key} is missing" }
if prefix.responds_to?(:value)
{to_s: prefix.to_s, value: prefix.value}
else
{to_s: prefix.to_s, value: prefix}
end
end