Create a type to output a key-value pair

This commit is contained in:
Michael Miller 2019-02-28 16:46:50 -07:00
parent 4e3290ebfe
commit 1610d6ebe3
2 changed files with 16 additions and 5 deletions

View file

@ -63,11 +63,7 @@ module Spectator::Formatters
indent do
@result.expectations.each_unsatisfied do |expectation|
expectation.values.each do |key, value|
line(io) do
io << key
io << ": "
io << value
end
line(io) { io << MatchDataValuePair.new(key, value) }
end
end
end

View file

@ -0,0 +1,15 @@
module Spectator::Formatters
# A single key-value pair from the `Spectator::Matchers::MatchData#value` method.
private struct MatchDataValuePair(T)
# Creates the pair formatter.
def initialize(@key : Symbol, @value : T)
end
# Appends the pair to the output.
def to_s(io)
io << @key
io << ": "
io << @value
end
end
end