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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
fn always_return_true() -> bool { true }
fn main() {
always_return_true();
}
#[cfg(test)]
mod tests {
use super::always_return_true;
use laboratory::{describe, expect, LabResult, NullState};
#[test]
fn test() -> LabResult {
// In this suite we want to use hooks to
// perform actions before and after our tests.
// The actions we want to run in this scenario is simply
// outputting to stdout.
describe("always_return_true()", |suite| {
// We want to run this action before all
// all tests in this suite is ran. This action
// will only be ran once.
suite.before_all(|_| {
println!("\n\n before_all hook called");
})
// We want to run this action just before every test
// in this suite (and child suites). Since we have two tests this action
// will be ran twice.
.before_each(|_| {
println!(" before_each hook called");
})
// likewise, we also have actions we want to run
// after our tests.
.after_each(|_| {
println!(" after_each hook called");
}).after_all(|_| {
println!(" after_all hook called");
})
.it("should return true", |_| {
expect(always_return_true()).to_be(true)
})
.it("should return true again", |_| {
expect(always_return_true()).to_be(true)
});
}).state(NullState).run()
}
}