class Spectator::SpecBuilder
- Spectator::SpecBuilder
- Reference
- Object
Overview
Progressively builds a test spec.
A stack is used to track the current example group. Adding an example or group will nest it under the group at the top of the stack.
Defined in:
spectator/spec_builder.crConstant Summary
-
Log =
::Spectator::Log.for(self)
Constructors
-
.new(config : Config)
Creates a new spec builder.
Instance Method Summary
-
#add_example(name, location, context_builder, metadata = nil, &block : Example -> _) : Nil
Defines a new example.
-
#add_pending_example(name, location, metadata = nil, reason = nil) : Nil
Defines a new pending example.
- #after_all(*args, **options)
- #after_all(*args, **options, &)
- #after_each(*args, **options)
- #after_each(*args, **options, &)
-
#after_suite(*args, **kwargs) : Nil
Registers a new "after_suite" hook.
-
#after_suite(*args, **kwargs, &block) : Nil
Registers a new "after_suite" hook.
- #around_each(*args, **options)
- #around_each(*args, **options, &)
- #before_all(*args, **options)
- #before_all(*args, **options, &)
- #before_each(*args, **options)
- #before_each(*args, **options, &)
-
#before_suite(*args, **kwargs) : Nil
Registers a new "before_suite" hook.
-
#before_suite(*args, **kwargs, &block) : Nil
Registers a new "before_suite" hook.
-
#build : Spec
Constructs the test spec.
-
#end_group : Nil
Completes a previously defined example group and pops it off the group stack.
- #post_condition(*args, **options)
- #post_condition(*args, **options, &)
- #pre_condition(*args, **options)
- #pre_condition(*args, **options, &)
-
#start_group(name, location = nil, metadata = nil) : Nil
Defines a new example group and pushes it onto the group stack.
-
#start_iterative_group(collection, name, iterator = nil, location = nil, metadata = nil) : Nil
Defines a new iterative example group and pushes it onto the group stack.
Instance methods inherited from class Object
should(matcher : Spectator::Matchers::TypeMatcher(U), message = nil, *, _file = __FILE__, _line = __LINE__) forall Ushould(matcher, message = nil, *, _file = __FILE__, _line = __LINE__) should, should_eventually(matcher, message = nil, *, _file = __FILE__, _line = __LINE__) should_eventually, should_never(matcher, message = nil, *, _file = __FILE__, _line = __LINE__) should_never, should_not(matcher : Spectator::Matchers::TypeMatcher(U), message = nil, *, _file = __FILE__, _line = __LINE__) forall U
should_not(matcher : Spectator::Matchers::NilMatcher, message = nil, *, _file = __FILE__, _line = __LINE__)
should_not(matcher, message = nil, *, _file = __FILE__, _line = __LINE__) should_not
Constructor Detail
Creates a new spec builder. A root group is pushed onto the group stack.
Instance Method Detail
Defines a new example. The example is added to the group currently on the top of the stack.
The name is the name or brief description of the example. This should be a string or nil. When nil, the example's name will be populated by the first expectation run inside of the test code.
The location optionally defined where the example originates in source code.
The context_builder is a proc that creates a context the test code should run in.
See Context
for more information.
A set of metadata can be used for filtering and modifying example behavior. For instance, adding a "pending" tag will mark the test as pending and skip execution.
A block must be provided. It will be yielded two arguments - the example created by this method, and the context argument. The return value of the block is ignored. It is expected that the test code runs when the block is called.
Defines a new pending example. The example is added to the group currently on the top of the stack.
The name is the name or brief description of the example. This should be a string or nil. When nil, the example's name will be an anonymous example reference.
The location optionally defined where the example originates in source code.
A set of metadata can be used for filtering and modifying example behavior. For instance, adding a "pending" tag will mark the test as pending and skip execution. A default reason can be given in case the user didn't provide one.
Registers a new "after_suite" hook.
The hook will be pre-pended to the list.
A new hook will be created by passing args to ExampleGroupHook.new
.
Registers a new "after_suite" hook.
The hook will be pre-pended to the list.
A new hook will be created by passing args to ExampleGroupHook.new
.
Registers a new "before_suite" hook.
The hook will be appended to the list.
A new hook will be created by passing args to ExampleGroupHook.new
.
Registers a new "before_suite" hook.
The hook will be appended to the list.
A new hook will be created by passing args to ExampleGroupHook.new
.
Constructs the test spec. Returns the spec instance.
Raises an error if there were not symmetrical calls to #start_group
and #end_group
.
This would indicate a logical error somewhere in Spectator or an extension of it.
Completes a previously defined example group and pops it off the group stack.
Be sure to call #start_group
and #end_group
symmetrically.
Defines a new example group and pushes it onto the group stack.
Examples and groups defined after calling this method will be nested under the new group.
The group will be finished and popped off the stack when #end_example
is called.
The name is the name or brief description of the group. This should be a symbol when describing a type - the type name is represented as a symbol. Otherwise, a string should be used.
The location optionally defined where the group originates in source code.
A set of metadata can be used for filtering and modifying example behavior. For instance, adding a "pending" tag will mark tests as pending and skip execution.
Defines a new iterative example group and pushes it onto the group stack.
Examples and groups defined after calling this method will be nested under the new group.
The group will be finished and popped off the stack when #end_example
is called.
The collection is the set of items to iterate over. Child nodes in this group will be executed once for every item in the collection. The name should be a string representation of collection. The iterator is an optional name given to a single item in collection.
The location optionally defined where the group originates in source code.
A set of metadata can be used for filtering and modifying example behavior. For instance, adding a "pending" tag will mark tests as pending and skip execution.