WIP display all expectations

Display the error stacktrace after expectations if the result is an 
ErroredResult.
This commit is contained in:
Michael Miller 2019-03-03 09:48:44 -07:00
parent 66c1dc3bce
commit f73a51ae0c

View file

@ -58,38 +58,42 @@ module Spectator::Formatting
end end
# Produces the main content of the failure block. # Produces the main content of the failure block.
# Any failed expectations are displayed,
# then an error stacktrace if an error occurred.
private def content(io) private def content(io)
io.puts io.puts
if(@result.is_a?(ErroredResult)) indent do
stack_trace(io) unsatisfied_expectations(io)
else error_stacktrace(io) if @result.is_a?(ErroredResult)
values(io)
end end
io.puts io.puts
end end
# Produces the values list of the failure block. # Produces a list of unsatisfied expectations and their values.
private def values(io) private def unsatisfied_expectations(io)
indent do @result.expectations.each_unsatisfied do |expectation|
@result.expectations.each_unsatisfied do |expectation| # TODO: Failure message for this expectation.
MatchDataValues.new(expectation.values).each do |pair| matcher_values(io, expectation)
line(io, Color.failure(pair)) end
end end
end
# Produces the values list for an expectation
private def matcher_values(io, expectation)
MatchDataValues.new(expectation.values).each do |pair|
# TODO: Not all expectations will be failures (color green and red).
line(io, Color.failure(pair))
end end
end end
# Produces the stack trace for an errored result. # Produces the stack trace for an errored result.
private def stack_trace(io) private def error_stacktrace(io)
error = @result.error error = @result.error
indent do loop do
loop do display_error(io, error)
display_error(io, error) if (next_error = error.cause)
if (next_error = error.cause) error = next_error
error = next_error else
else break
break
end
end end
end end
end end