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
- Enumerable(Spectator::ExampleComponent)
- Iterable(Spectator::ExampleComponent)
Direct Known Subclasses
Defined in:
spectator/example_group.crConstructors
Instance Method Summary
-
#[](index : Int) : Example
Retrieves an example by its index.
-
#children : Array(ExampleComponent)
Retrieves the children in the group.
-
#children=(children : Array(ExampleComponent))
Sets the children of the group.
-
#children? : Array(ExampleComponent) | Nil
Retrieves the children in the group.
- #context : Spectator::TestContext
- #double(id, sample_values)
-
#each(&)
Yields each direct descendant.
-
#each : Iterator(ExampleComponent)
Returns an iterator for each direct descendant.
-
#example_count : Int
Number of examples in this group and all sub-groups.
-
#finished? : Bool
Checks whether all examples in the group have been run.
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
Instance Method Detail
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.
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.
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.
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.