Move message line inside content

This allows for multiple message lines for multiple expectations.
This commit is contained in:
Michael Miller 2019-03-03 10:11:46 -07:00
parent 238dc38a36
commit 2c5da0c345
1 changed files with 19 additions and 26 deletions

View File

@ -27,7 +27,6 @@ module Spectator::Formatting
indent.increase do indent.increase do
title(indent) title(indent)
indent.increase(inner_indent) do indent.increase(inner_indent) do
message(indent)
content(indent) content(indent)
source(indent) source(indent)
end end
@ -43,35 +42,24 @@ module Spectator::Formatting
indent.line(NumberedItem.new(@index, @result.example)) indent.line(NumberedItem.new(@index, @result.example))
end end
# Produces the message line of the failure block.
# The line takes the form:
# ```text
# Failure: Error message
# ```
# The indentation of this line starts directly under
# the example name from the title line.
private def message(indent)
indent.line(FailureMessage.color(@result))
end
# Produces the main content of the failure block. # Produces the main content of the failure block.
# Any failed expectations are displayed, # Any failed expectations are displayed,
# then an error stacktrace if an error occurred. # then an error stacktrace if an error occurred.
private def content(indent) private def content(indent)
indent.line
indent.increase do
unsatisfied_expectations(indent) unsatisfied_expectations(indent)
error_stacktrace(indent) if @result.is_a?(ErroredResult) error_stacktrace(indent) if @result.is_a?(ErroredResult)
end end
indent.line
end
# 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|
# TODO: Failure message for this expectation. indent.line(FailureMessage.color(@result))
indent.line
indent.increase do
matcher_values(indent, expectation) matcher_values(indent, expectation)
end end
indent.line
end
end end
# Produces the values list for an expectation # Produces the values list for an expectation
@ -84,7 +72,10 @@ module Spectator::Formatting
# Produces the stack trace for an errored result. # Produces the stack trace for an errored result.
private def error_stacktrace(indent) private def error_stacktrace(indent)
indent.line(FailureMessage.color(@result))
indent.line
error = @result.error error = @result.error
indent.increase do
loop do loop do
display_error(indent, error) display_error(indent, error)
if (next_error = error.cause) if (next_error = error.cause)
@ -94,6 +85,8 @@ module Spectator::Formatting
end end
end end
end end
indent.line
end
# Display a single error and its stacktrace. # Display a single error and its stacktrace.
private def display_error(indent, error) : Nil private def display_error(indent, error) : Nil