Struct rspec::block::context::Context [−][src]
Test contexts are a convenient tool for adding structure and code sharing to a test suite.
Implementations
impl<T> Context<T>
[src]
pub fn num_blocks(&self) -> usize
[src]
pub fn num_examples(&self) -> usize
[src]
pub fn is_empty(&self) -> bool
[src]
impl<T> Context<T> where
T: Clone,
[src]
T: Clone,
pub fn context<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:
pub fn specify<F>(&mut self, name: &'static str, body: F) where
F: FnOnce(&mut Context<T>),
T: Debug,
[src]
F: FnOnce(&mut Context<T>),
T: Debug,
pub fn when<F>(&mut self, name: &'static str, body: F) where
F: FnOnce(&mut Context<T>),
T: Debug,
[src]
F: FnOnce(&mut Context<T>),
T: Debug,
pub 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"'
.
pub fn example<F, U>(&mut self, name: &'static str, body: F) where
F: 'static + Fn(&T) -> U,
U: Into<ExampleResult>,
[src]
F: 'static + Fn(&T) -> U,
U: Into<ExampleResult>,
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:
pub fn it<F, U>(&mut self, name: &'static str, body: F) where
F: 'static + Fn(&T) -> U,
U: Into<ExampleResult>,
[src]
F: 'static + Fn(&T) -> U,
U: Into<ExampleResult>,
pub fn then<F, U>(&mut self, name: &'static str, body: F) where
F: 'static + Fn(&T) -> U,
U: Into<ExampleResult>,
[src]
F: 'static + Fn(&T) -> U,
U: Into<ExampleResult>,
pub 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:
pub 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.
pub 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":
…
pub 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:
pub 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.
pub 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
Auto Trait Implementations
impl<T> !RefUnwindSafe for Context<T>
[src]
impl<T> Unpin for Context<T>
[src]
impl<T> !UnwindSafe for Context<T>
[src]
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> Pointable for T
pub const ALIGN: usize
type Init = T
The type for initializers.
pub unsafe fn init(init: <T as Pointable>::Init) -> usize
pub unsafe fn deref<'a>(ptr: usize) -> &'a T
pub unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T
pub unsafe fn drop(ptr: usize)
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,