diff --git a/src/spectator/formatting/components/fail_result_block.cr b/src/spectator/formatting/components/fail_result_block.cr index 77f536d..74b2f60 100644 --- a/src/spectator/formatting/components/fail_result_block.cr +++ b/src/spectator/formatting/components/fail_result_block.cr @@ -7,14 +7,12 @@ require "./result_block" module Spectator::Formatting::Components # Displays information about a fail result. struct FailResultBlock < ResultBlock - @expectation : Expectation @longest_key : Int32 # 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) - @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 # Content displayed on the second line of the block after the label. diff --git a/src/spectator/formatting/summary.cr b/src/spectator/formatting/summary.cr index 7007b88..29dccb2 100644 --- a/src/spectator/formatting/summary.cr +++ b/src/spectator/formatting/summary.cr @@ -41,7 +41,14 @@ module Spectator::Formatting if result = example.result.as?(ErrorResult) io.puts Components::ErrorResultBlock.new(example, index, result) 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