File: multi.rs

package info (click to toggle)
rust-rspec 1.0.0-2
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 312 kB
  • sloc: makefile: 4
file content (40 lines) | stat: -rw-r--r-- 1,332 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
extern crate rspec;

use std::io;
use std::sync::Arc;

// An example of a single runner running multiple semantically equivalent,
// yet syntactically different test suites in succession:

pub fn main() {
    let logger = Arc::new(rspec::Logger::new(io::stdout()));
    let configuration = rspec::ConfigurationBuilder::default().build().unwrap();
    let runner = rspec::Runner::new(configuration, vec![logger]);

    // A test suite using the `suite`, `context`, `example` syntax family:
    runner.run(&rspec::suite("an value of ten", 10, |ctx| {
        ctx.context("adding 5 to it", |ctx| {
            ctx.example("results in fifteen", |num| {
                assert_eq!(*num, 15);
            });
        });
    }));

    // A test suite using the `describe`, `specify`, `it` syntax family:
    runner.run(&rspec::describe("an value of ten", 10, |ctx| {
        ctx.specify("adding 5 to it", |ctx| {
            ctx.it("results in fifteen", |num| {
                assert_eq!(*num, 15);
            });
        });
    }));

    // A test suite using the `given`, `when`, `then` syntax family:
    runner.run(&rspec::given("an value of ten", 10, |ctx| {
        ctx.when("adding 5 to it", |ctx| {
            ctx.then("results in fifteen", |num| {
                assert_eq!(*num, 15);
            });
        });
    }));
}