Struct rspec::block::Context
[−]
[src]
pub struct Context<T> { /* fields omitted */ }
Test contexts are a convenient tool for adding structure and code sharing to a test suite.
Methods
impl<T> Context<T>
[src]
fn num_blocks(&self) -> usize
[src]
fn num_examples(&self) -> usize
[src]
fn is_empty(&self) -> bool
[src]
impl<T> Context<T> where
T: Clone,
[src]
T: Clone,
fn context<'a, F>(&mut self, name: &'static str, body: F) where
F: FnOnce(&mut Context<T>),
T: Debug,
[src]
F: FnOnce(&mut Context<T>),
T: Debug,
Open and name a new context within the current context.
Note that the order of execution IS NOT guaranteed to match the declaration order.
Examples
runner.run(&rspec::suite("a test suite", (), |ctx| { ctx.context("opens a context labeled 'context'", |_ctx| { // … }); }));
Corresponding console output:
tests:
Suite "a test suite":
Context "opens a sub-context":
…
Available aliases:
fn specify<'a, F>(&mut self, name: &'static str, body: F) where
F: FnOnce(&mut Context<T>),
T: Debug,
[src]
F: FnOnce(&mut Context<T>),
T: Debug,
fn when<'b, F>(&mut self, name: &'static str, body: F) where
F: FnOnce(&mut Context<T>),
T: Debug,
[src]
F: FnOnce(&mut Context<T>),
T: Debug,
fn scope<F>(&mut self, body: F) where
F: FnOnce(&mut Context<T>),
T: Debug,
[src]
F: FnOnce(&mut Context<T>),
T: Debug,
Open a new name-less context within the current context which won't show up in the logs.
This can be useful for adding additional structure (and before
/after
blocks) to your
tests without their labels showing up as noise in the console output.
As such one might want to selectively assign two contexts/examples an additional before
block without them getting visually separated from their neighboring contexts/examples.
Examples
runner.run(&rspec::suite("a suite",(), |ctx| { ctx.context("a context", |ctx| { ctx.scope(|ctx| { ctx.example("an example", |_env| { // … }); }); }); }));
Corresponding console output:
tests:
Suite "a suite":
Context "a context":
Example "an example"
The before_each(…)
block gets executed before 'It "tests a"'
and 'It "tests a"'
,
but not before 'It "tests c"'
.
fn example<F, U>(&mut self, name: &'static str, body: F) where
F: 'static + Fn(&T) -> U,
U: Into<ExampleReport>,
[src]
F: 'static + Fn(&T) -> U,
U: Into<ExampleReport>,
Open and name a new example within the current context.
Note that the order of execution IS NOT guaranteed to match the declaration order.
Examples
runner.run(&rspec::suite("a test suite", (), |ctx| { ctx.example("an example", |_env| { // … }); }));
Corresponding console output:
tests:
Suite "a test suite":
Example "an example":
…
Available aliases:
fn it<F, U>(&mut self, name: &'static str, body: F) where
F: 'static + Fn(&T) -> U,
U: Into<ExampleReport>,
[src]
F: 'static + Fn(&T) -> U,
U: Into<ExampleReport>,
fn then<F, U>(&mut self, name: &'static str, body: F) where
F: 'static + Fn(&T) -> U,
U: Into<ExampleReport>,
[src]
F: 'static + Fn(&T) -> U,
U: Into<ExampleReport>,
fn before_all<F>(&mut self, body: F) where
F: 'static + Fn(&mut T),
[src]
F: 'static + Fn(&mut T),
Declares a closure that will be executed once before any of the context's children (context or example blocks) are being executed.
Note that the order of execution IS NOT guaranteed to match the declaration order.
Examples
runner.run(&rspec::suite("a test suite", (), |ctx| { ctx.before_all(|_env| { // … }); ctx.example("an example", |_env| { // … }); ctx.example("another example", |_env| { // … }); }));
Corresponding console output:
tests:
Suite "a test suite":
Example "an example":
…
Example "another example":
…
Available aliases:
fn before<F>(&mut self, body: F) where
F: 'static + Fn(&mut T),
[src]
F: 'static + Fn(&mut T),
Alias for before_all
, see for more info.
fn before_each<F>(&mut self, body: F) where
F: 'static + Fn(&mut T),
[src]
F: 'static + Fn(&mut T),
Declares a closure that will be executed once before each of the context's children (context or example blocks).
Note that the order of execution IS NOT guaranteed to match the declaration order.
Examples
runner.run(&rspec::suite("a test suite", (), |ctx| { ctx.before_each(|_env| { // … }); ctx.example("an example", |_env| { // … }); ctx.example("another example", |_env| { // … }); }));
Corresponding console output:
tests:
Suite "a test suite":
Example "an example":
…
Example "another example":
…
fn after_all<F>(&mut self, body: F) where
F: 'static + Fn(&mut T),
[src]
F: 'static + Fn(&mut T),
Declares a closure that will be executed once after any of the context's children (context or example blocks) have been executed.
Note that the order of execution IS NOT guaranteed to match the declaration order.
Examples
runner.run(&rspec::suite("a test suite", (), |ctx| { ctx.after_all(|_env| { // … }); ctx.example("an example", |_env| { // … }); ctx.example("another example", |_env| { // … }); }));
Corresponding console output:
tests:
Suite "a test suite":
Example "an example":
…
Example "another example":
…
Available aliases:
fn after<F>(&mut self, body: F) where
F: 'static + Fn(&mut T),
[src]
F: 'static + Fn(&mut T),
Alias for after_all
, see for more info.
fn after_each<F>(&mut self, body: F) where
F: 'static + Fn(&mut T),
[src]
F: 'static + Fn(&mut T),
Declares a closure that will be executed once after each of the context's children (context or example blocks).
Note that the order of execution IS NOT guaranteed to match the declaration order.
Examples
runner.run(&rspec::suite("a test suite", (), |ctx| { ctx.after_each(|_env| { // … }); ctx.example("an example", |_env| { // … }); ctx.example("another example", |_env| { // … }); }));
Corresponding console output:
tests:
Suite "a test suite":
Example "an example":
…
Example "another example":
…
Trait Implementations
impl<T> Send for Context<T> where
T: Send,
[src]
T: Send,
impl<T> Sync for Context<T> where
T: Sync,
[src]
T: Sync,