From eade6873e4405c775f9209b625366a7a2d8b5a49 Mon Sep 17 00:00:00 2001 From: Michael Miller Date: Sun, 14 Oct 2018 18:37:54 -0600 Subject: [PATCH] Implement ExampleComponent#example_count --- src/spectator/example.cr | 5 +++++ src/spectator/example_component.cr | 3 +++ src/spectator/example_group.cr | 7 ++----- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/spectator/example.cr b/src/spectator/example.cr index 62d6dd8..bcb58f8 100644 --- a/src/spectator/example.cr +++ b/src/spectator/example.cr @@ -29,6 +29,11 @@ module Spectator def initialize(@group, sample_values : Internals::SampleValues) end + # Indicates there is only one example to run. + def example_count + 1 + end + # String representation of the example. # This consists of the groups the example is in and the description. # The string can be given to end-users to identify the example. diff --git a/src/spectator/example_component.cr b/src/spectator/example_component.cr index 9862a87..fdb24d7 100644 --- a/src/spectator/example_component.cr +++ b/src/spectator/example_component.cr @@ -7,5 +7,8 @@ module Spectator # Indicates whether the example (or group) has been completely run. abstract def finished? : Bool + + # The number of examples in this instance. + abstract def example_count : Int end end diff --git a/src/spectator/example_group.cr b/src/spectator/example_group.cr index c49fca1..9c63633 100644 --- a/src/spectator/example_group.cr +++ b/src/spectator/example_group.cr @@ -27,11 +27,8 @@ module Spectator children.each end - # TODO: Remove this method. - def example_count - children.sum do |child| - child.is_a?(Example) ? 1 : child.as(ExampleGroup).example_count - end + def example_count : Int + children.sum(&.example_count) end # TODO: Remove this method.