Module rspec::context [] [src]

The Context module holds all the functionality for the test declaration, that is: describe, before, after, it and their variants.

A Context can also holds reference to children Contextes, for whom the before closures will be executed after the before closures of the current context. The order of execution of tests respect the order of declaration of theses tests.

Running these tests and doing asserts is not the job of the Context, but the Runner, which is a struct returned by the root context declaration.

Examples

use rspec::context::*;

// `rdescribe` instanciate a runner and run it transparently
rdescribe("Context", |ctx| {
    describe("Context::describe", |ctx| {
        ctx.it("can be nested", || Ok(()) as Result<(),()>);
        ctx.it("use a `ctx` object", || Ok(()) as Result<(),()>)
    });

    describe("Context::it", |ctx| {
        ctx.it("uses a Result returns", || Ok(()) as Result<(),()>);
        ctx.it("can also use asserts", || {
            assert_eq!(42, 12 + 30);
            Ok(()) as Result<(),()> // don't forget the result type
        })
    });
});

Structs

Context

A Context holds a collection of tests, a collection of closures to call before running any tests, and a collection of closure to call after all the tests..

Enums

Testable

This enum is used to build a tree of named tests and contextes.

Functions

describe

This is the root describe. It will instanciate a root Context that you can use to declare examples, and will returns a Runner ready to run the tests.

rdescribe

This is the root describe with a sugar. It will instanciate a root Context that you can use to declare examples, will instanciate a Runner for the test and run them.

Type Definitions

AfterFunction

This is the type used by the closure given as argument of a Context::after() call.

BeforeFunction

This is the type used by the closure given as argument of a Context::before() call.

TestFunction

This is the type used by the closure given as argument of a Context::it() call.

TestResult

The type used for a test result