From 6d8d117ec245ae57311da314dc75fd788d84c102 Mon Sep 17 00:00:00 2001 From: Michael Miller Date: Sat, 29 May 2021 17:50:30 -0600 Subject: [PATCH] Handle nodes with no name --- src/spectator/formatting/document_formatter.cr | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/spectator/formatting/document_formatter.cr b/src/spectator/formatting/document_formatter.cr index 99fb689..fe6c1ce 100644 --- a/src/spectator/formatting/document_formatter.cr +++ b/src/spectator/formatting/document_formatter.cr @@ -12,6 +12,9 @@ module Spectator::Formatting # Identation string. private INDENT = " " + # String used for groups and examples that don't have a name. + private NO_NAME = "" + # Output stream to write results to. private getter io @@ -34,19 +37,22 @@ module Spectator::Formatting # Invoked after an example completes successfully. # Produces a successful example line. def example_passed(notification) - line(notification.example.name.colorize(:green)) + name = (notification.example.name? || NO_NAME) + line(name.colorize(:green)) end # Invoked after an example is skipped or marked as pending. # Produces a pending example line. def example_pending(notification) - line(notification.example.name.colorize(:yellow)) + name = (notification.example.name? || NO_NAME) + line(name.colorize(:yellow)) end # Invoked after an example fails. # Produces a failure example line. def example_failed(notification) - line(notification.example.name.colorize(:red)) + name = (notification.example.name? || NO_NAME) + line(name.colorize(:red)) end # Invoked after an example fails from an unexpected error. @@ -60,7 +66,7 @@ module Spectator::Formatting Array(Label).new.tap do |hierarchy| group = example.group? while group && (parent = group.group?) - hierarchy << group.name + hierarchy << (group.name? || NO_NAME) group = parent end hierarchy.reverse!