multi/
multi.rs

1extern crate rspec;
2
3use std::io;
4use std::sync::Arc;
5
6// An example of a single runner running multiple semantically equivalent,
7// yet syntactically different test suites in succession:
8
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}