mirror of
https://gitea.invidious.io/iv-org/shard-spectator.git
synced 2024-08-15 00:53:35 +00:00
Replace FailureMessage with LabeledText
This commit is contained in:
parent
2c5da0c345
commit
df71e56b3e
3 changed files with 18 additions and 38 deletions
|
@ -53,7 +53,7 @@ module Spectator::Formatting
|
|||
# Produces a list of unsatisfied expectations and their values.
|
||||
private def unsatisfied_expectations(indent)
|
||||
@result.expectations.each_unsatisfied do |expectation|
|
||||
indent.line(FailureMessage.color(@result))
|
||||
indent.line(Color.failure(LabeledText.new("Failure", expectation.actual_message)))
|
||||
indent.line
|
||||
indent.increase do
|
||||
matcher_values(indent, expectation)
|
||||
|
@ -72,9 +72,9 @@ module Spectator::Formatting
|
|||
|
||||
# Produces the stack trace for an errored result.
|
||||
private def error_stacktrace(indent)
|
||||
indent.line(FailureMessage.color(@result))
|
||||
indent.line
|
||||
error = @result.error
|
||||
indent.line(Color.error(LabeledText.new("Error", error)))
|
||||
indent.line
|
||||
indent.increase do
|
||||
loop do
|
||||
display_error(indent, error)
|
||||
|
|
|
@ -1,35 +0,0 @@
|
|||
module Spectator::Formatting
|
||||
# Produces a stringified failure or error message.
|
||||
private struct FailureMessage
|
||||
# Creates the failure message.
|
||||
def initialize(@result : FailedResult)
|
||||
end
|
||||
|
||||
# Appends the message to the output.
|
||||
def to_s(io)
|
||||
io << @result.call(Label)
|
||||
io << @result.error
|
||||
end
|
||||
|
||||
# Creates a colorized version of the message.
|
||||
def self.color(result)
|
||||
result.call(Color) { |result| new(result) }
|
||||
end
|
||||
|
||||
# Interface for `Result#call` to invoke.
|
||||
# This is used to get the correct prefix for failures and errors.
|
||||
private module Label
|
||||
extend self
|
||||
|
||||
# Returns the prefix for a failure message.
|
||||
def failure
|
||||
"Failure: "
|
||||
end
|
||||
|
||||
# Returns the prefix for an error message.
|
||||
def error
|
||||
"Error: "
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
15
src/spectator/formatting/labeled_text.cr
Normal file
15
src/spectator/formatting/labeled_text.cr
Normal file
|
@ -0,0 +1,15 @@
|
|||
module Spectator::Formatting
|
||||
# Produces a stringified message with a prefix.
|
||||
private struct LabeledText(T)
|
||||
# Creates the labeled text.
|
||||
def initialize(@label : String, @text : T)
|
||||
end
|
||||
|
||||
# Appends the message to the output.
|
||||
def to_s(io)
|
||||
io << @label
|
||||
io << ": "
|
||||
io << @text
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue