Interceptor

Trait Interceptor 

Source
pub trait Interceptor: Send + Sync {
    // Required method
    fn intercept(
        &self,
        name: &str,
        args: &[Value],
    ) -> Option<Result<Value, ExecError>>;
}
Expand description

Something that answers a call instead of the definition it names.

This exists for exactly one caller, and the reason it is on the seam rather than inside a backend is docs/21-tests-in-beck-and-proof.md §21.3: “A mock is not a stand-in for an object. It is a value for an effect.” A stub is therefore not a program transformation the compiler can do once — the complete list of what got stubbed has to be reportable per test, with the arguments each stubbed call was passed, because §21.3 rule 4 makes verification a query over what happened rather than an expectation set in advance.

A backend that cannot offer this says so by returning None from Backend::intercepting, and the harness reports that stubs are unavailable rather than running the test and lying about it.

Required Methods§

Source

fn intercept( &self, name: &str, args: &[Value], ) -> Option<Result<Value, ExecError>>

Called before a top-level definition named name is applied to args. Returning Some replaces the call; returning None runs the real body.

The answer is a Result because a definition’s failure is one of its answers: a stub stands in for the definition, so it stands in for the raises(E) its signature already declares (docs/22 §22.6). Err carrying an ExecError::raise unwinds exactly as the real body’s raise would, so the program’s own try: catches it; Err without one is a fault in the stub itself.

Implementors§