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 [], 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

def self.new(hooks : ExampleHooks, conditions : ExampleConditions) #

Creates the example group. The hooks are stored to be triggered later.


[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 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]
def run_after_hooks #

Runs all of the "after-all" and "after-each" hooks. This should run following every example in the group.


[View source]
def run_before_hooks #

Runs all of the "before-each" and "before-all" hooks. This should run prior to every example in the group.


[View source]
def run_post_conditions #

Runs all of the post-conditions for an example.


[View source]
def run_pre_conditions #

Runs all of the pre-conditions for an example.


[View source]
def wrap_around_each_hooks(&block : -> ) : -> #

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.


[View source]