Trait subplotlib::prelude::ContextElement
source · [−]pub trait ContextElement: Debug + Default + Send + 'static {
fn created(&mut self, scenario: &Scenario) { ... }
fn scenario_starts(&mut self) -> StepResult { ... }
fn scenario_stops(&mut self) -> StepResult { ... }
fn step_starts(&mut self, step_title: &str) -> StepResult { ... }
fn step_stops(&mut self) -> StepResult { ... }
}
Expand description
A context element is anything which can be used as a scenario step context.
Contexts get called whenever the scenario steps occur so that they can do prep, cleanup, etc. It’s important for authors of context element types to be aware that they won’t always be called on scenario start and they will not be caught up the first time they are invoked for a step, simply expected to get on with life from their first use.
Provided Methods
A new context element was created.
In order to permit elements which for example work on disk, this function will be invoked with the scenario’s context to permit the context to register other contexts it might need, or to permit the creation of suitably named temporary directories, logging, etc.
The scenario’s title is available via scenario_context.title()
fn scenario_starts(&mut self) -> StepResult
fn scenario_starts(&mut self) -> StepResult
Scenario starts
When a scenario starts, this function is called to permit setup.
If this returns an error, scenario setup is stopped and scenario_stops
will be called for anything which succeeded at startup.
fn scenario_stops(&mut self) -> StepResult
fn scenario_stops(&mut self) -> StepResult
Scenario stops
When a scenario finishes, this function is called to permit teardown.
If this returns an error, and the scenario would otherwise have passed, then the error will be used. The first encountered error in stopping a scenario will be used, rather than the last. All contexts which succeeded at starting will be stopped.
fn step_starts(&mut self, step_title: &str) -> StepResult
fn step_starts(&mut self, step_title: &str) -> StepResult
Entry to a step function
In order to permit elements which for example work on disk, this function will be invoked with the step’s name to permit the creation of suitably named temporary directories, logging, etc.
The default implementation of this does nothing.
Calls to this function will be paired with calls to the step exit function providing nothing panics or calls exit without unwinding.
If you wish to be resilient to step functions panicing then you will need to be careful to cope with a new step being entered without a previous step exiting. Particularly if you’re handing during cleanup of a failed scenario.
If this returns an error then the step function is not run, nor is the
corresponding exit_step()
called.
fn step_stops(&mut self) -> StepResult
fn step_stops(&mut self) -> StepResult
Exit from a step function
See the step_starts
function for most
details of this.
Any error returned from this will be masked if the step function itself returned an error. However if the step function succeeded then this function’s error will make it out.