class Spectator::Harness
- Spectator::Harness
- Reference
- Object
Overview
Helper class that acts as a gateway between test code and the framework.
Test code should be wrapped with a call to .run
.
This class will catch all errors raised by the test code.
Errors caused by failed assertions (AssertionFailed
) are translated to failed results (FailResult
).
Errors not caused by assertions are translated to error results (ErrorResult
).
Every runnable example should invoke the test code by calling .run
.
This sets up the harness so that the test code can use it.
The framework does the following:
result = Harness.run { run_example_code }
# Do something with the result.
Then from the test code, the harness can be accessed via .current
like so:
harness = ::Spectator::Harness.current
# Do something with the harness.
Of course, the end-user shouldn't see this or work directly with the harness. Instead, methods the test calls can access it. For instance, an expectation reporting a result.
Defined in:
spectator/harness.crConstant Summary
-
Log =
::Spectator::Log.for(self)
Constructors
-
.current : self
Retrieves the harness for the current running example.
Class Method Summary
-
.current? : self | Nil
Retrieves the harness for the current running example.
-
.run(&) : Result
Wraps an example with a harness and runs test code.
Instance Method Summary
- #aggregate_failures(label = nil, &)
-
#cleanup(&block) : Nil
Stores a block of code to be executed at cleanup.
-
#defer(&block) : Nil
Stores a block of code to be executed later.
- #report(expectation : Expectation) : Bool
-
#run(&) : Result
Runs test code and produces a result based on the outcome.
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
Class Method Detail
Wraps an example with a harness and runs test code.
A block provided to this method is considered to be the test code.
The value of .current
is set to the harness for the duration of the test.
It will be reset after the test regardless of the outcome.
The result of running the test code will be returned.
Instance Method Detail
Stores a block of code to be executed at cleanup. Cleanup is run after everything else, even deferred blocks. Each cleanup step is wrapped in error handling so that one failure doesn't block the next ones.
Stores a block of code to be executed later.
All deferred blocks run just before the #run
method completes.
Runs test code and produces a result based on the outcome. The test code should be called from within the block given to this method.