[go: up one dir, main page]

suite

Function suite 

Source
pub fn suite<F, T>(name: &'static str, environment: T, body: F) -> Suite<T>
where F: FnOnce(&mut Context<T>), T: Clone + Debug,
Expand description

Creates a test suite from a given root context.

§Examples

runner.run(&rspec::suite("a test suite", (), |_ctx| {
    // …
}));

Corresponding console output:

tests
Suite "a test suite":
    …

Available aliases:

Examples found in repository?
examples/multi.rs (lines 15-21)
9pub fn main() {
10    let logger = Arc::new(rspec::Logger::new(io::stdout()));
11    let configuration = rspec::ConfigurationBuilder::default().build().unwrap();
12    let runner = rspec::Runner::new(configuration, vec![logger]);
13
14    // A test suite using the `suite`, `context`, `example` syntax family:
15    runner.run(&rspec::suite("an value of ten", 10, |ctx| {
16        ctx.context("adding 5 to it", |ctx| {
17            ctx.example("results in fifteen", |num| {
18                assert_eq!(*num, 15);
19            });
20        });
21    }));
22
23    // A test suite using the `describe`, `specify`, `it` syntax family:
24    runner.run(&rspec::describe("an value of ten", 10, |ctx| {
25        ctx.specify("adding 5 to it", |ctx| {
26            ctx.it("results in fifteen", |num| {
27                assert_eq!(*num, 15);
28            });
29        });
30    }));
31
32    // A test suite using the `given`, `when`, `then` syntax family:
33    runner.run(&rspec::given("an value of ten", 10, |ctx| {
34        ctx.when("adding 5 to it", |ctx| {
35            ctx.then("results in fifteen", |num| {
36                assert_eq!(*num, 15);
37            });
38        });
39    }));
40}