Handle nodes with no name

This commit is contained in:
Michael Miller 2021-05-29 17:50:30 -06:00
parent 4a44d038fb
commit 6d8d117ec2
No known key found for this signature in database
GPG key ID: FB9F12F7C646A4AD

View file

@ -12,6 +12,9 @@ module Spectator::Formatting
# Identation string. # Identation string.
private INDENT = " " private INDENT = " "
# String used for groups and examples that don't have a name.
private NO_NAME = "<anonymous>"
# Output stream to write results to. # Output stream to write results to.
private getter io private getter io
@ -34,19 +37,22 @@ module Spectator::Formatting
# Invoked after an example completes successfully. # Invoked after an example completes successfully.
# Produces a successful example line. # Produces a successful example line.
def example_passed(notification) def example_passed(notification)
line(notification.example.name.colorize(:green)) name = (notification.example.name? || NO_NAME)
line(name.colorize(:green))
end end
# Invoked after an example is skipped or marked as pending. # Invoked after an example is skipped or marked as pending.
# Produces a pending example line. # Produces a pending example line.
def example_pending(notification) def example_pending(notification)
line(notification.example.name.colorize(:yellow)) name = (notification.example.name? || NO_NAME)
line(name.colorize(:yellow))
end end
# Invoked after an example fails. # Invoked after an example fails.
# Produces a failure example line. # Produces a failure example line.
def example_failed(notification) def example_failed(notification)
line(notification.example.name.colorize(:red)) name = (notification.example.name? || NO_NAME)
line(name.colorize(:red))
end end
# Invoked after an example fails from an unexpected error. # Invoked after an example fails from an unexpected error.
@ -60,7 +66,7 @@ module Spectator::Formatting
Array(Label).new.tap do |hierarchy| Array(Label).new.tap do |hierarchy|
group = example.group? group = example.group?
while group && (parent = group.group?) while group && (parent = group.group?)
hierarchy << group.name hierarchy << (group.name? || NO_NAME)
group = parent group = parent
end end
hierarchy.reverse! hierarchy.reverse!