Support output of multiple failed expectations

This commit is contained in:
Michael Miller 2021-06-12 11:59:57 -06:00
parent 88f0c23a3e
commit 621ddb466f
No known key found for this signature in database
GPG key ID: FB9F12F7C646A4AD
2 changed files with 10 additions and 5 deletions

View file

@ -7,14 +7,12 @@ require "./result_block"
module Spectator::Formatting::Components module Spectator::Formatting::Components
# Displays information about a fail result. # Displays information about a fail result.
struct FailResultBlock < ResultBlock struct FailResultBlock < ResultBlock
@expectation : Expectation
@longest_key : Int32 @longest_key : Int32
# Creates the component. # Creates the component.
def initialize(example : Example, index : Int32, result : FailResult, subindex = 0) def initialize(example : Example, index : Int32, @expectation : Expectation, subindex = 0)
super(example, index, subindex) super(example, index, subindex)
@expectation = result.expectations.find(&.failed?).not_nil! @longest_key = expectation.values.max_of { |(key, _value)| key.to_s.size }
@longest_key = @expectation.values.max_of { |(key, _value)| key.to_s.size }
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.

View file

@ -41,7 +41,14 @@ module Spectator::Formatting
if result = example.result.as?(ErrorResult) if result = example.result.as?(ErrorResult)
io.puts Components::ErrorResultBlock.new(example, index, result) io.puts Components::ErrorResultBlock.new(example, index, result)
elsif result = example.result.as?(FailResult) elsif result = example.result.as?(FailResult)
io.puts Components::FailResultBlock.new(example, index, result) 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 end
end end
end end