mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Display failed expectations and error if an example had both
This commit is contained in:
parent
621ddb466f
commit
02a4b2946e
3 changed files with 27 additions and 14 deletions
|
@ -7,8 +7,8 @@ module Spectator::Formatting::Components
|
|||
# Displays information about an error result.
|
||||
struct ErrorResultBlock < ResultBlock
|
||||
# Creates the component.
|
||||
def initialize(example : Example, index : Int32, @result : ErrorResult)
|
||||
super(example, index)
|
||||
def initialize(example : Example, index : Int32, @result : ErrorResult, subindex = 0)
|
||||
super(example, index, subindex)
|
||||
end
|
||||
|
||||
# Content displayed on the second line of the block after the label.
|
||||
|
|
|
@ -74,6 +74,7 @@ module Spectator::Formatting::Components::JUnit
|
|||
# Adds an error element to the test case node.
|
||||
def error(result)
|
||||
error = result.error
|
||||
fail(result) # Include failed expectations.
|
||||
@xml.element("error", message: error.message, type: error.class) do
|
||||
if backtrace = error.backtrace
|
||||
@xml.text(backtrace.join("\n"))
|
||||
|
|
|
@ -38,18 +38,7 @@ module Spectator::Formatting
|
|||
io.puts "Failures:"
|
||||
io.puts
|
||||
examples.each_with_index(1) do |example, index|
|
||||
if result = example.result.as?(ErrorResult)
|
||||
io.puts Components::ErrorResultBlock.new(example, index, result)
|
||||
elsif result = example.result.as?(FailResult)
|
||||
failed_expectations = result.expectations.select(&.failed?)
|
||||
if failed_expectations.size == 1
|
||||
io.puts Components::FailResultBlock.new(example, index, failed_expectations.first)
|
||||
else
|
||||
failed_expectations.each_with_index(1) do |expectation, subindex|
|
||||
io.puts Components::FailResultBlock.new(example, index, expectation, subindex)
|
||||
end
|
||||
end
|
||||
end
|
||||
dump_failed_example(example, index)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -70,5 +59,28 @@ module Spectator::Formatting
|
|||
|
||||
io.puts Components::FailureCommandList.new(failures)
|
||||
end
|
||||
|
||||
# Displays one or more blocks for a failed example.
|
||||
# Each block is a failed expectation or error raised in the example.
|
||||
private def dump_failed_example(example, index)
|
||||
result = example.result.as?(ErrorResult)
|
||||
failed_expectations = example.result.expectations.select(&.failed?)
|
||||
block_count = failed_expectations.size
|
||||
block_count += 1 if result
|
||||
|
||||
# Don't use sub-index if there was only one problem.
|
||||
if block_count == 1
|
||||
if result
|
||||
io.puts Components::ErrorResultBlock.new(example, index, result)
|
||||
else
|
||||
io.puts Components::FailResultBlock.new(example, index, failed_expectations.first)
|
||||
end
|
||||
else
|
||||
failed_expectations.each_with_index(1) do |expectation, subindex|
|
||||
io.puts Components::FailResultBlock.new(example, index, expectation, subindex)
|
||||
end
|
||||
io.puts Components::ErrorResultBlock.new(example, index, result, block_count) if result
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue