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]

[src]

[src]

[src]

impl<T> Context<T> where
    T: Clone
[src]

[src]

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:

[src]

Alias for context, see for more info.

Available further aliases:

[src]

Alias for context, see for more info.

Available further aliases:

[src]

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"'.

[src]

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:

[src]

Alias for example, see for more info.

Available further aliases:

[src]

Alias for example, see for more info.

Available further aliases:

[src]

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:

[src]

Alias for before_all, see for more info.

[src]

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":
        …

[src]

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:

[src]

Alias for after_all, see for more info.

[src]

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]

impl<T> Sync for Context<T> where
    T: Sync
[src]

impl<T> Default for Context<T>
[src]

[src]

Returns the "default value" for a type. Read more