Skip to main content

Driver

Trait Driver 

Source
pub trait Driver {
    // Required methods
    fn set(&mut self, var: &Variable, value: &Value) -> Result<(), String>;
    fn perform(&mut self, event: &Event) -> Result<(), String>;
    fn observe(&mut self, var: &Variable) -> Result<Value, String>;

    // Provided methods
    fn needs(&self) -> Vec<String> { ... }
    fn fresh(&self) -> Vec<String> { ... }
    fn reset(&mut self) -> Result<(), String> { ... }
    fn arrange(&mut self, var: &Variable, value: &Value) -> Result<(), String> { ... }
    fn can_arrange(&self, var: &Variable, value: &Value) -> bool { ... }
    fn settle(&mut self) { ... }
    fn advance(&mut self) -> Progress { ... }
    fn screenshot(&mut self) -> Result<Option<Screenshot>, String> { ... }
    fn supports(&self, need: Need<'_>) -> bool { ... }
}
Expand description

Drives the system under test in the vocabulary’s terms.

Calls may block. A real-time system (a game, a simulation) can let time pass in Driver::advance and the runner keeps observing until a step’s checks hold or its patience runs out, so “Then the kettle is heating” means eventually, as it would for a person watching.

Required Methods§

Source

fn set(&mut self, var: &Variable, value: &Value) -> Result<(), String>

Make var hold value as an action (“When the dial is 80 %”).

Source

fn perform(&mut self, event: &Event) -> Result<(), String>

Make event happen (“When the user presses reset”).

Source

fn observe(&mut self, var: &Variable) -> Result<Value, String>

What var is now. Enumerated values are matched to the vocabulary ignoring case.

Provided Methods§

Source

fn needs(&self) -> Vec<String>

The external services this driver needs for its tests (see crate::service): a controller, a database. The runner starts them before a plan, and when one cannot be had here the plans are “not supported yet”, with what to do about it.

Source

fn fresh(&self) -> Vec<String>

The services that must be started afresh before each test (a database the last test wrote to): a subset of Driver::needs.

Source

fn reset(&mut self) -> Result<(), String>

Put the system in its starting state (what the Background describes), before each test.

Source

fn arrange(&mut self, var: &Variable, value: &Value) -> Result<(), String>

Make var hold value before the first step (“Given …”).

Source

fn can_arrange(&self, var: &Variable, value: &Value) -> bool

Can it put var in value to start a test? Driver::supports only knows the state; a driver that can arrange some of its values and not others (a test account that can’t be emptied can’t start with no messages) says so here, and the tests that need the rest are “not supported yet” instead of failing.

Source

fn settle(&mut self)

Let the system settle after an action, before anything is observed: long enough for what should happen to happen, and for what shouldn’t to show. Without it, “Then the kettle is off” could pass in the instant before it switches on.

Source

fn advance(&mut self) -> Progress

Let a little time pass before the runner observes again.

Source

fn screenshot(&mut self) -> Result<Option<Screenshot>, String>

Source

fn supports(&self, need: Need<'_>) -> bool

Can it do need? The runner checks every plan up front, so a missing binding fails the test before it starts instead of halfway through.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl<W> Driver for Bindings<W>