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
-
.new(hooks : ExampleHooks, conditions : ExampleConditions)
Creates the example group.
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.
-
#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.
-
#run_after_hooks
Runs all of the "after-all" and "after-each" hooks.
-
#run_before_hooks
Runs all of the "before-each" and "before-all" hooks.
-
#run_post_conditions
Runs all of the post-conditions for an example.
-
#run_pre_conditions
Runs all of the pre-conditions for an example.
-
#wrap_around_each_hooks(&block : -> ) : ->
Creates a proc that runs the "around-each" hooks in addition to a block passed to this method.
Instance methods inherited from class Spectator::ExampleComponent
[](index : Int) : Example
[],
example_count : Int
example_count,
finished? : Bool
finished?,
symbolic? : Bool
symbolic?,
what : Symbol | String
what
Instance methods inherited from class Object
should(matcher : Spectator::Matchers::Matcher)
should,
should_not(matcher : Spectator::Matchers::Matcher)
should_not
Constructor Detail
Creates the example group. The hooks are stored to be triggered later.
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.
Runs all of the "after-all" and "after-each" hooks. This should run following every example in the group.
Runs all of the "before-each" and "before-all" hooks. This should run prior to every example in the group.
Creates a proc that runs the "around-each" hooks
in addition to a block passed to this method.
To call the block and all "around-each" hooks,
just invoke Proc#call
on the returned proc.