abstract class Spectator::ExampleGroup

Overview

Shared base class for groups of examples.

Represents a collection of examples and other groups. Use the #each methods to iterate through each child. However, these methods do not recurse into sub-groups. If you need that functionality, see ExampleIterator. Additionally, the indexer method (#[]) will index into sub-groups.

This class also stores hooks to be associated with all examples in the group. The hooks can be invoked by running the #run_before_hooks and #run_after_hooks methods.

Included Modules

Direct Known Subclasses

Defined in:

spectator/example_group.cr

Constructors

Instance Method Summary

Instance methods inherited from class Spectator::ExampleComponent

[](index : Int) : Example [], description : Symbol | String description, example_count : Int example_count, finished? : Bool finished?, full_description full_description, source : Source source, symbolic? : Bool symbolic?

Instance methods inherited from class Object

should(matcher) should, should_eventually(matcher) should_eventually, should_never(matcher) should_never, should_not(matcher) should_not

Constructor Detail

def self.new(context : TestContext) #

[View source]

Instance Method Detail

def [](index : Int) : Example #

Retrieves an example by its index. This recursively searches for an example.

Positive and negative indices can be used. Any value out of range will raise an IndexError.

Examples are indexed as if they are in a flattened tree. For instance:

examples = [0, 1, [2, 3, 4], [5, [6, 7], 8], 9, [10]].flatten

The arrays symbolize groups, and the numbers are the index of the example in that slot.


[View source]
def children : Array(ExampleComponent) #

Retrieves the children in the group. This only returns the direct descends (non-recursive). The children must be set (with #children=) prior to calling this method.


[View source]
def children=(children : Array(ExampleComponent)) #

Sets the children of the group. This should be called only from a builder in the DSL namespace. The children can be set only once - attempting to set more than once will raise an error. All sub-groups' children should be set before setting this group's children.


[View source]
def children? : Array(ExampleComponent) | Nil #

Retrieves the children in the group. This only returns the direct descends (non-recursive). The children must be set (with #children=) prior to calling this method.


[View source]
def context : Spectator::TestContext #

[View source]
def double(id, sample_values) #

[View source]
def each(&) #

Yields each direct descendant.


[View source]
def each : Iterator(ExampleComponent) #

Returns an iterator for each direct descendant.


[View source]
def example_count : Int #

Number of examples in this group and all sub-groups.


[View source]
def finished? : Bool #

Checks whether all examples in the group have been run.


[View source]