mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Show match data in failure block
This commit is contained in:
parent
a5ed5d0fb1
commit
ba3a03736e
1 changed files with 25 additions and 3 deletions
|
@ -1,19 +1,25 @@
|
||||||
require "colorize"
|
require "colorize"
|
||||||
require "../../example"
|
require "../../example"
|
||||||
|
require "../../expectation"
|
||||||
require "../../fail_result"
|
require "../../fail_result"
|
||||||
require "./result_block"
|
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
|
||||||
|
|
||||||
# Creates the component.
|
# Creates the component.
|
||||||
def initialize(index : Int32, example : Example, @result : FailResult)
|
def initialize(index : Int32, example : Example, result : FailResult)
|
||||||
super(index, example)
|
super(index, example)
|
||||||
|
@expectation = result.expectations.find(&.failed?).not_nil!
|
||||||
|
@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.
|
||||||
private def subtitle
|
private def subtitle
|
||||||
@result.error.message.try(&.each_line.first)
|
@expectation.failure_message
|
||||||
end
|
end
|
||||||
|
|
||||||
# Prefix for the second line of the block.
|
# Prefix for the second line of the block.
|
||||||
|
@ -23,7 +29,23 @@ module Spectator::Formatting::Components
|
||||||
|
|
||||||
# Display expectation match data.
|
# Display expectation match data.
|
||||||
private def content(io)
|
private def content(io)
|
||||||
# TODO: Display match data.
|
indent do
|
||||||
|
@expectation.values.each do |(key, value)|
|
||||||
|
value_line(io, key, value)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
io.puts
|
||||||
|
end
|
||||||
|
|
||||||
|
# Display a single line for a match data value.
|
||||||
|
private def value_line(io, key, value)
|
||||||
|
key = key.to_s
|
||||||
|
padding = " " * (@longest_key - key.size)
|
||||||
|
|
||||||
|
line(io) do
|
||||||
|
io << padding << key.colorize(:red) << ": ".colorize(:red) << value
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue