Update formatting to use Tuple

This commit is contained in:
Michael Miller 2019-08-08 21:57:02 -06:00
parent 9dc5a999d1
commit 353e5f6886
3 changed files with 9 additions and 9 deletions

View file

@ -53,7 +53,7 @@ module Spectator::Formatting
# Produces a list of unsatisfied expectations and their values. # Produces a list of unsatisfied expectations and their values.
private def unsatisfied_expectations(indent) private def unsatisfied_expectations(indent)
@result.expectations.each_unsatisfied do |expectation| @result.expectations.each_unsatisfied do |expectation|
indent.line(Color.failure(LabeledText.new("Failure", expectation.actual_message))) indent.line(Color.failure(LabeledText.new("Failure", expectation.failure_message)))
indent.line indent.line
indent.increase do indent.increase do
matcher_values(indent, expectation) matcher_values(indent, expectation)

View file

@ -19,7 +19,7 @@ module Spectator::Formatting
private def content(xml) private def content(xml)
super super
@result.expectations.each_unsatisfied do |expectation| @result.expectations.each_unsatisfied do |expectation|
xml.element("failure", message: expectation.actual_message) do xml.element("failure", message: expectation.failure_message) do
expectation_values(expectation.values, xml) expectation_values(expectation.values, xml)
end end
end end
@ -28,8 +28,8 @@ module Spectator::Formatting
# Adds the expectation values to the failure block. # Adds the expectation values to the failure block.
private def expectation_values(labeled_values, xml) private def expectation_values(labeled_values, xml)
labeled_values.each do |entry| labeled_values.each do |entry|
label = entry.label label = entry.first
value = entry.value value = entry.last
xml.text("#{label}: #{value}\n") xml.text("#{label}: #{value}\n")
end end
end end

View file

@ -2,22 +2,22 @@ module Spectator::Formatting
# Produces a `MatchDataValuePair` for each key-value pair # Produces a `MatchDataValuePair` for each key-value pair
# from `Spectator::Matchers::MatchData#values`. # from `Spectator::Matchers::MatchData#values`.
private struct MatchDataValues private struct MatchDataValues
include Enumerable(MatchDataValuePair) include Enumerable(Tuple(Symbol, String))
@max_key_length : Int32 @max_key_length : Int32
# Creates the values mapper. # Creates the values mapper.
def initialize(@values : Array(Spectator::Matchers::MatchDataLabeledValue)) def initialize(@values : Array(Tuple(Symbol, String)))
@max_key_length = @values.map(&.label.to_s.size).max @max_key_length = @values.map(&.first.to_s.size).max
end end
# Yields pairs that can be printed to output. # Yields pairs that can be printed to output.
def each def each
@values.each do |labeled_value| @values.each do |labeled_value|
key = labeled_value.label key = labeled_value.first
key_length = key.to_s.size key_length = key.to_s.size
padding = @max_key_length - key_length padding = @max_key_length - key_length
yield MatchDataValuePair.new(key, labeled_value.value, padding) yield MatchDataValuePair.new(key, labeled_value.last, padding)
end end
end end
end end