mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
ErrorResultBlock only needs the exception, not an ErrorResult
This commit is contained in:
parent
d10531430c
commit
027521a7bc
2 changed files with 19 additions and 20 deletions
|
@ -7,13 +7,13 @@ module Spectator::Formatting::Components
|
||||||
# Displays information about an error result.
|
# Displays information about an error result.
|
||||||
struct ErrorResultBlock < ResultBlock
|
struct ErrorResultBlock < ResultBlock
|
||||||
# Creates the component.
|
# Creates the component.
|
||||||
def initialize(example : Example, index : Int32, @result : ErrorResult, subindex = 0)
|
def initialize(example : Example, index : Int32, @error : Exception, subindex = 0)
|
||||||
super(example, index, subindex)
|
super(example, index, subindex)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Content displayed on the second line of the block after the label.
|
# Content displayed on the second line of the block after the label.
|
||||||
private def subtitle
|
private def subtitle
|
||||||
@result.error.message.try(&.each_line.first)
|
@error.message.try(&.each_line.first)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Prefix for the second line of the block.
|
# Prefix for the second line of the block.
|
||||||
|
@ -24,19 +24,18 @@ module Spectator::Formatting::Components
|
||||||
# Display error information.
|
# Display error information.
|
||||||
private def content(io)
|
private def content(io)
|
||||||
# Fetch the error and message.
|
# Fetch the error and message.
|
||||||
error = @result.error
|
lines = @error.message.try(&.lines)
|
||||||
lines = error.message.try(&.lines)
|
|
||||||
|
|
||||||
# Write the error and message if available.
|
# Write the error and message if available.
|
||||||
case
|
case
|
||||||
when lines.nil? then write_error_class(io, error)
|
when lines.nil? then write_error_class(io)
|
||||||
when lines.size == 1 then write_error_message(io, error, lines.first)
|
when lines.size == 1 then write_error_message(io, lines.first)
|
||||||
when lines.size > 1 then write_multiline_error_message(io, error, lines)
|
when lines.size > 1 then write_multiline_error_message(io, lines)
|
||||||
else write_error_class(io, error)
|
else write_error_class(io)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Display the backtrace if it's available.
|
# Display the backtrace if it's available.
|
||||||
if backtrace = error.backtrace?
|
if backtrace = @error.backtrace?
|
||||||
indent { write_backtrace(io, backtrace) }
|
indent { write_backtrace(io, backtrace) }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -44,24 +43,24 @@ module Spectator::Formatting::Components
|
||||||
end
|
end
|
||||||
|
|
||||||
# Display just the error type.
|
# Display just the error type.
|
||||||
private def write_error_class(io, error)
|
private def write_error_class(io)
|
||||||
line(io) do
|
line(io) do
|
||||||
io << error.class.colorize(:red)
|
io << @error.class.colorize(:red)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Display the error type and first line of the message.
|
# Display the error type and first line of the message.
|
||||||
private def write_error_message(io, error, message)
|
private def write_error_message(io, message)
|
||||||
line(io) do
|
line(io) do
|
||||||
io << "#{error.class}: ".colorize(:red)
|
io << "#{@error.class}: ".colorize(:red)
|
||||||
io << message
|
io << message
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Display the error type and its multi-line message.
|
# Display the error type and its multi-line message.
|
||||||
private def write_multiline_error_message(io, error, lines)
|
private def write_multiline_error_message(io, lines)
|
||||||
# Use the normal formatting for the first line.
|
# Use the normal formatting for the first line.
|
||||||
write_error_message(io, error, lines.first)
|
write_error_message(io, lines.first)
|
||||||
|
|
||||||
# Display additional lines after the first.
|
# Display additional lines after the first.
|
||||||
lines.skip(1).each do |entry|
|
lines.skip(1).each do |entry|
|
||||||
|
|
|
@ -63,15 +63,15 @@ module Spectator::Formatting
|
||||||
# Displays one or more blocks for a failed example.
|
# Displays one or more blocks for a failed example.
|
||||||
# Each block is a failed expectation or error raised in the example.
|
# Each block is a failed expectation or error raised in the example.
|
||||||
private def dump_failed_example(example, index)
|
private def dump_failed_example(example, index)
|
||||||
result = example.result.as?(ErrorResult)
|
error = example.result.as?(ErrorResult).try(&.error)
|
||||||
failed_expectations = example.result.expectations.select(&.failed?)
|
failed_expectations = example.result.expectations.select(&.failed?)
|
||||||
block_count = failed_expectations.size
|
block_count = failed_expectations.size
|
||||||
block_count += 1 if result
|
block_count += 1 if error
|
||||||
|
|
||||||
# Don't use sub-index if there was only one problem.
|
# Don't use sub-index if there was only one problem.
|
||||||
if block_count == 1
|
if block_count == 1
|
||||||
if result
|
if error
|
||||||
io.puts Components::ErrorResultBlock.new(example, index, result)
|
io.puts Components::ErrorResultBlock.new(example, index, error)
|
||||||
else
|
else
|
||||||
io.puts Components::FailResultBlock.new(example, index, failed_expectations.first)
|
io.puts Components::FailResultBlock.new(example, index, failed_expectations.first)
|
||||||
end
|
end
|
||||||
|
@ -79,7 +79,7 @@ module Spectator::Formatting
|
||||||
failed_expectations.each_with_index(1) do |expectation, subindex|
|
failed_expectations.each_with_index(1) do |expectation, subindex|
|
||||||
io.puts Components::FailResultBlock.new(example, index, expectation, subindex)
|
io.puts Components::FailResultBlock.new(example, index, expectation, subindex)
|
||||||
end
|
end
|
||||||
io.puts Components::ErrorResultBlock.new(example, index, result, block_count) if result
|
io.puts Components::ErrorResultBlock.new(example, index, error, block_count) if error
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue