class

Spectator::ExampleGroup

Inherits Iterable < Enumerable < Spectator::ExampleComponent < Reference < Object

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.

Constructors

new(context : TestContext)
Source

Instance methods

[](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.

Source
children

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.

Source
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.

Source
children?

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.

Source
context
Source
double(id, sample_values)
Source
each

Yields each direct descendant.

Source
each

Returns an iterator for each direct descendant.

Source
example_count

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

Source
finished?

Checks whether all examples in the group have been run.

Source