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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
mod matchers;
mod assertions;
use time::Duration;
use dsl::assertions::*;
use dsl::matchers::*;
pub trait Assertion<A> {
fn to<M: Matcher<A>>(self, matcher: M);
fn not_to<M: Matcher<A>>(self, matcher: M);
}
pub trait AsyncAssertion<A> {
fn should<M: Matcher<A>>(self, matcher: M);
fn should_not<M: Matcher<A>>(self, matcher: M);
}
impl<A, B> AsyncAssertion<A> for B where B: Assertion<A> {
fn should<M: Matcher<A>>(self, matcher: M) {
self.to(matcher);
}
fn should_not<M: Matcher<A>>(self, matcher: M) {
self.not_to(matcher);
}
}
pub trait Matcher<A> {
fn matches(&self, actual: &A) -> bool;
fn failure_message(&self, actual: &A) -> String;
fn negated_failure_message(&self, actual: &A) -> String;
}
pub fn expect<'a, A>(actual: &'a A) -> Expect<'a, A> {
Expect::new(actual)
}
pub fn eventually<F, A>(f: F) -> Async<A> where F: 'static + Fn() -> A {
let timeout = Duration::seconds(1);
eventually_with_timeout(timeout, f)
}
pub fn eventually_with_timeout<F, A>(timeout: Duration, f: F)
-> Async<A> where F: 'static + Fn() -> A {
Async::new(AsyncType::Eventual, timeout, f)
}
pub fn consistently<F, A>(f: F) -> Async<A> where F: 'static + Fn() -> A {
let timeout = Duration::seconds(1);
consistently_with_timeout(timeout, f)
}
pub fn consistently_with_timeout<F, A>(timeout: Duration, f: F)
-> Async<A> where F: 'static + Fn() -> A {
Async::new(AsyncType::Consistent, timeout, f)
}
pub fn equal<'a, E>(expected: &'a E) -> Equals<'a, E> {
Equals::new(expected)
}
pub fn contain<'a, E>(expected: &'a E) -> Contain<'a, E> {
Contain::new(expected)
}
pub fn be_some() -> OptionMatcher {
OptionMatcher::SomeMatch
}
pub fn be_none() -> OptionMatcher {
OptionMatcher::NoneMatch
}
pub fn be_ok() -> ResultMatcher {
ResultMatcher::OkMatch
}
pub fn be_err() -> ResultMatcher {
ResultMatcher::ErrMatch
}