Move value enumeration to another type

This commit is contained in:
Michael Miller 2019-02-28 19:49:23 -07:00
parent 0fce18a610
commit cc3392022e
2 changed files with 20 additions and 2 deletions

View file

@ -62,8 +62,8 @@ module Spectator::Formatting
io.puts
indent do
@result.expectations.each_unsatisfied do |expectation|
expectation.values.each do |key, value|
line(io, MatchDataValuePair.new(key, value))
MatchDataValues.new(expectation.values).each do |pair|
line(io, Color.failure(pair))
end
end
end

View file

@ -0,0 +1,18 @@
module Spectator::Formatting
# Produces a `MatchDataValuePair` for each key-value pair
# from `Spectator::Matchers::MatchData#values`.
private struct MatchDataValues(T)
include Enumerable(MatchDataValuePair)
# Creates the values mapper.
def initialize(@values : T)
end
# Yields pairs that can be printed to output.
def each
@values.each do |key, value|
yield MatchDataValuePair.new(key, value)
end
end
end
end