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
fn main() {
add_one(0);
}
fn add_one (n: u64) -> u64 { n + 1 }
#[cfg(test)]
mod tests {
use std::borrow::BorrowMut;
use super::*;
use laboratory::{describe, expect, LabResult, NullState};
#[test]
fn suite() -> LabResult {
// just as there is a context for the suite, there is
// also a context for each spec. And that context can be
// accessed from the callback closure. However, since the test would
// be immediately ran, whatever options you would like to include
// will not be included until after the test is completed.
// So, the suite also provides a spec() method where a
// developer can include any additional options on a per spec
// basis before the test is ran.
// Options such as:
// skip(),
// retries()
// slow()
describe("add_one()", |suite| {
suite.spec(|spec| {
spec.it("should retry ten times", |spec| {
println!("attempt number: {}", spec.attempts);
if spec.attempts < 10 {
Err(String::from("not enough attempts have been performed"))
} else {
Ok(())
}
}).retries(9).slow(1000);
})
.it("should return 2 when passed 1", |_| {
expect(add_one(1)).to_equal(2)
});
}).state(NullState).milis().run()
}
}