Skip to content

Commit 3174ae4

Browse files
committed
Always instantiace matchers with their contructors in tests
1 parent 6bff461 commit 3174ae4

File tree

6 files changed

+41
-113
lines changed

6 files changed

+41
-113
lines changed

src/matchers.rs

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -46,39 +46,32 @@ impl<E: std::fmt::Debug, A: PartialEq<E> + std::fmt::Debug> Matcher<A> for Equal
4646
#[cfg(test)]
4747
mod tests {
4848
use super::equal;
49-
use super::EqualMatcher;
50-
use crate::expect;
5149
use crate::Matcher;
5250

5351
#[test]
5452
fn should_match_if_actual_equals_expected() {
55-
assert!(EqualMatcher { expected: "foo" }.match_value(&"foo"))
53+
assert!(equal("foo").match_value(&"foo"))
5654
}
5755

5856
#[test]
5957
fn should_not_match_if_actual_does_not_equal_expected() {
60-
assert!(!EqualMatcher { expected: "foo" }.match_value(&"bar"))
58+
assert!(!equal("foo").match_value(&"bar"))
6159
}
6260

6361
#[test]
6462
fn should_allow_comparisons_between_partialeq_values() {
65-
assert!(EqualMatcher { expected: "foo" }.match_value(&String::from("foo")));
63+
assert!(equal("foo").match_value(&String::from("foo")));
6664
}
6765

6866
#[test]
6967
fn failure_messages() {
7068
assert_eq!(
71-
EqualMatcher { expected: "foo" }.failure_message(&"bar"),
69+
equal("foo").failure_message(&"bar"),
7270
String::from("\tExpected:\n\t\t\"bar\"\n\tto equal:\n\t\t\"foo\"")
7371
);
7472
assert_eq!(
75-
EqualMatcher { expected: "foo" }.negated_failure_message(&"foo"),
73+
equal("foo").negated_failure_message(&"foo"),
7674
String::from("\tExpected:\n\t\t\"foo\"\n\tnot to equal:\n\t\t\"foo\"")
7775
);
7876
}
79-
80-
#[test]
81-
fn equal_should_construct_an_equal_matcher() {
82-
expect(&"foo").to(equal("foo"))
83-
}
8477
}

src/matchers/collection.rs

Lines changed: 10 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -183,76 +183,53 @@ impl<T: std::cmp::Ord> Collection<T> for std::collections::BTreeSet<T> {
183183

184184
#[cfg(test)]
185185
mod tests {
186-
use super::{be_empty, contain, BeEmptyMatcher, Collection, ContainMatcher};
187-
use crate::{expect, Matcher};
188-
use std::marker::PhantomData;
186+
use super::{be_empty, contain, Collection};
187+
use crate::Matcher;
189188

190189
#[test]
191190
fn contain_matcher_should_match_if_collection_contains_element() {
192-
assert!(ContainMatcher { element: "foo" }.match_value(&vec!["foo"]))
191+
assert!(contain("foo").match_value(&vec!["foo"]))
193192
}
194193

195194
#[test]
196195
fn contain_matcher_should_not_match_if_collection_does_not_contain_element() {
197-
assert!(!ContainMatcher { element: "foo" }.match_value(&vec!["bar"]))
196+
assert!(!contain("foo").match_value(&vec!["bar"]))
198197
}
199198

200199
#[test]
201200
fn contain_matcher_failure_messages() {
202201
assert_eq!(
203-
ContainMatcher { element: "foo" }.failure_message(&vec!["bar"]),
202+
contain("foo").failure_message(&vec!["bar"]),
204203
String::from("\tExpected:\n\t\t[\"bar\"]\n\tto contain:\n\t\t\"foo\"")
205204
);
206205
assert_eq!(
207-
ContainMatcher { element: "foo" }.negated_failure_message(&vec!["foo"]),
206+
contain("foo").negated_failure_message(&vec!["foo"]),
208207
String::from("\tExpected:\n\t\t[\"foo\"]\n\tnot to contain:\n\t\t\"foo\"")
209208
);
210209
}
211210

212-
#[test]
213-
fn contain_should_construct_a_contain_matcher() {
214-
expect(&vec!["foo", "bar"]).to(contain("foo"))
215-
}
216-
217211
#[test]
218212
fn be_empty_matcher_should_match_if_collection_is_empty() {
219-
assert!(BeEmptyMatcher {
220-
phantom: PhantomData
221-
}
222-
.match_value(&std::vec::Vec::<i32>::new()))
213+
assert!(be_empty().match_value(&std::vec::Vec::<i32>::new()))
223214
}
224215

225216
#[test]
226217
fn be_empty_matcher_should_not_match_if_collection_is_not_empty() {
227-
assert!(!BeEmptyMatcher {
228-
phantom: PhantomData
229-
}
230-
.match_value(&vec![42]))
218+
assert!(!be_empty().match_value(&vec![42]))
231219
}
232220

233221
#[test]
234222
fn be_empty_matcher_failure_messages() {
235223
assert_eq!(
236-
BeEmptyMatcher {
237-
phantom: PhantomData
238-
}
239-
.failure_message(&vec!["bar"]),
224+
be_empty().failure_message(&vec!["bar"]),
240225
String::from("\tExpected:\n\t\t[\"bar\"]\n\tto be empty")
241226
);
242227
assert_eq!(
243-
BeEmptyMatcher {
244-
phantom: PhantomData
245-
}
246-
.negated_failure_message(&std::vec::Vec::<i32>::new()),
228+
be_empty().negated_failure_message(&std::vec::Vec::<i32>::new()),
247229
String::from("\tExpected:\n\t\t[]\n\tnot to be empty")
248230
);
249231
}
250232

251-
#[test]
252-
fn be_empty_should_construct_a_be_empty_matcher() {
253-
expect(&std::vec::Vec::<i32>::new()).to(be_empty())
254-
}
255-
256233
#[test]
257234
fn arrays_with_up_to_256_elements_are_collections() {
258235
assert!([

src/matchers/option.rs

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -64,64 +64,50 @@ impl<T: std::cmp::PartialEq + std::fmt::Debug> Matcher<Option<T>> for NoneMatche
6464

6565
#[cfg(test)]
6666
mod tests {
67-
use super::be_none;
68-
use super::be_some;
69-
use super::NoneMatcher;
70-
use super::SomeMatcher;
71-
use crate::expect;
67+
use super::{be_none, be_some};
7268
use crate::Matcher;
7369

7470
#[test]
7571
fn some_matcher_should_match_if_actual_is_some() {
76-
assert!(SomeMatcher {}.match_value(&Some("foo")))
72+
assert!(be_some().match_value(&Some("foo")))
7773
}
7874

7975
#[test]
8076
fn some_matcher_should_not_match_if_actual_is_none() {
81-
assert!(!SomeMatcher {}.match_value(&None::<u32>))
77+
assert!(!be_some().match_value(&None::<u32>))
8278
}
8379

8480
#[test]
8581
fn some_matcher_failure_messages() {
8682
assert_eq!(
87-
SomeMatcher {}.failure_message(&None::<&str>),
83+
be_some().failure_message(&None::<&str>),
8884
String::from("\tExpected:\n\t\tNone\n\tto be a Some")
8985
);
9086
assert_eq!(
91-
SomeMatcher {}.negated_failure_message(&Some("foo")),
87+
be_some().negated_failure_message(&Some("foo")),
9288
String::from("\tExpected:\n\t\tSome(\"foo\")\n\tnot to be a Some")
9389
);
9490
}
9591

96-
#[test]
97-
fn be_some_should_contruct_a_some_matcher() {
98-
expect(&Some("thing")).to(be_some())
99-
}
100-
10192
#[test]
10293
fn none_matcher_should_match_if_actual_is_none() {
103-
assert!(NoneMatcher {}.match_value(&None::<&str>))
94+
assert!(be_none().match_value(&None::<&str>))
10495
}
10596

10697
#[test]
10798
fn none_matcher_should_not_match_if_actual_is_some() {
108-
assert!(!NoneMatcher {}.match_value(&Some("thing")))
99+
assert!(!be_none().match_value(&Some("thing")))
109100
}
110101

111102
#[test]
112103
fn none_matcher_failure_messages() {
113104
assert_eq!(
114-
NoneMatcher {}.failure_message(&Some("foo")),
105+
be_none().failure_message(&Some("foo")),
115106
String::from("\tExpected:\n\t\tSome(\"foo\")\n\tto be None")
116107
);
117108
assert_eq!(
118-
NoneMatcher {}.negated_failure_message(&None::<&str>),
109+
be_none().negated_failure_message(&None::<&str>),
119110
String::from("\tExpected:\n\t\tNone\n\tnot to be None")
120111
);
121112
}
122-
123-
#[test]
124-
fn be_none_should_contruct_a_none_matcher() {
125-
expect(&None::<&str>).to(be_none())
126-
}
127113
}

src/matchers/path.rs

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,34 +34,27 @@ impl<T: std::fmt::Debug + AsRef<Path>> Matcher<T> for ExistMatcher {
3434
#[cfg(test)]
3535
mod tests {
3636
use super::exist;
37-
use super::ExistMatcher;
38-
use crate::expect;
3937
use crate::Matcher;
4038

4139
#[test]
4240
fn should_match_if_actual_exists() {
43-
assert!(ExistMatcher {}.match_value(&"./Cargo.toml"))
41+
assert!(exist().match_value(&"./Cargo.toml"))
4442
}
4543

4644
#[test]
4745
fn should_not_match_if_actual_is_none() {
48-
assert!(!ExistMatcher {}.match_value(&"does_not_exist"))
46+
assert!(!exist().match_value(&"does_not_exist"))
4947
}
5048

5149
#[test]
5250
fn failure_messages() {
5351
assert_eq!(
54-
ExistMatcher {}.failure_message(&"does_not_exist"),
52+
exist().failure_message(&"does_not_exist"),
5553
String::from("\tExpected:\n\t\t\"does_not_exist\"\n\tto exist")
5654
);
5755
assert_eq!(
58-
ExistMatcher {}.negated_failure_message(&"does_exist"),
56+
exist().negated_failure_message(&"does_exist"),
5957
String::from("\tExpected:\n\t\t\"does_exist\"\n\tnot to exist")
6058
);
6159
}
62-
63-
#[test]
64-
fn exist_should_contruct_an_exist_matcher() {
65-
expect(&"./Cargo.toml").to(exist())
66-
}
6760
}

src/matchers/result.rs

Lines changed: 9 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -64,64 +64,50 @@ impl<T: std::fmt::Debug, E: std::fmt::Debug> Matcher<Result<T, E>> for ErrMatche
6464

6565
#[cfg(test)]
6666
mod tests {
67-
use super::be_err;
68-
use super::be_ok;
69-
use super::ErrMatcher;
70-
use super::OkMatcher;
71-
use crate::expect;
67+
use super::{be_err, be_ok};
7268
use crate::Matcher;
7369

7470
#[test]
7571
fn ok_matcher_should_match_if_actual_is_ok() {
76-
assert!(OkMatcher {}.match_value(&Ok::<u32, &str>(42)))
72+
assert!(be_ok().match_value(&Ok::<u32, &str>(42)))
7773
}
7874

7975
#[test]
8076
fn ok_matcher_should_not_match_if_actual_is_err() {
81-
assert!(!OkMatcher {}.match_value(&Err::<u32, &str>("boo")))
77+
assert!(!be_ok().match_value(&Err::<u32, &str>("boo")))
8278
}
8379

8480
#[test]
8581
fn ok_matcher_failure_messages() {
8682
assert_eq!(
87-
OkMatcher {}.failure_message(&Err::<u32, &str>("boo")),
83+
be_ok().failure_message(&Err::<u32, &str>("boo")),
8884
String::from("\tExpected:\n\t\tErr(\"boo\")\n\tto be Ok")
8985
);
9086
assert_eq!(
91-
OkMatcher {}.negated_failure_message(&Ok::<u32, &str>(42)),
87+
be_ok().negated_failure_message(&Ok::<u32, &str>(42)),
9288
String::from("\tExpected:\n\t\tOk(42)\n\tnot to be Ok")
9389
);
9490
}
9591

96-
#[test]
97-
fn be_ok_should_contruct_an_ok_matcher() {
98-
expect(&Ok::<u32, &str>(42)).to(be_ok())
99-
}
100-
10192
#[test]
10293
fn err_matcher_should_match_if_actual_is_an_err() {
103-
assert!(ErrMatcher {}.match_value(&Err::<u32, &str>("boo")))
94+
assert!(be_err().match_value(&Err::<u32, &str>("boo")))
10495
}
10596

10697
#[test]
10798
fn err_matcher_should_not_match_if_actual_is_ok() {
108-
assert!(!ErrMatcher {}.match_value(&Ok::<u32, &str>(42)))
99+
assert!(!be_err().match_value(&Ok::<u32, &str>(42)))
109100
}
110101

111102
#[test]
112103
fn err_matcher_failure_messages() {
113104
assert_eq!(
114-
ErrMatcher {}.failure_message(&Ok::<u32, &str>(42)),
105+
be_err().failure_message(&Ok::<u32, &str>(42)),
115106
String::from("\tExpected:\n\t\tOk(42)\n\tto be an Err")
116107
);
117108
assert_eq!(
118-
ErrMatcher {}.negated_failure_message(&Err::<u32, &str>("boo")),
109+
be_err().negated_failure_message(&Err::<u32, &str>("boo")),
119110
String::from("\tExpected:\n\t\tErr(\"boo\")\n\tnot to be an Err")
120111
);
121112
}
122-
123-
#[test]
124-
fn be_err_should_contruct_an_err_matcher() {
125-
expect(&Err::<u32, &str>("boo")).to(be_err())
126-
}
127113
}

src/matchers/string.rs

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -52,34 +52,27 @@ impl<A: AsRef<str> + std::fmt::Debug, E: AsRef<str> + std::fmt::Debug> Matcher<A
5252
#[cfg(test)]
5353
mod tests {
5454
use super::match_regex;
55-
use super::MatchRegexMatcher;
56-
use crate::expect;
5755
use crate::Matcher;
5856

5957
#[test]
6058
fn should_match_if_actual_matches_with_regex() {
61-
assert!(MatchRegexMatcher { regex: "foo.*" }.match_value(&"foobar"))
59+
assert!(match_regex("foo.*").match_value(&"foobar"))
6260
}
6361

6462
#[test]
6563
fn should_not_match_if_actual_does_not_match_regex() {
66-
assert!(!MatchRegexMatcher { regex: "foo.*" }.match_value(&"bar"))
64+
assert!(!match_regex("foo.*").match_value(&"bar"))
6765
}
6866

6967
#[test]
7068
fn failure_messages() {
7169
assert_eq!(
72-
MatchRegexMatcher { regex: "foo.*" }.failure_message(&"bar"),
70+
match_regex("foo.*").failure_message(&"bar"),
7371
String::from("\tExpected:\n\t\t\"bar\"\n\tto match regex:\n\t\t\"foo.*\"")
7472
);
7573
assert_eq!(
76-
MatchRegexMatcher { regex: "foo.*" }.negated_failure_message(&"foobar"),
74+
match_regex("foo.*").negated_failure_message(&"foobar"),
7775
String::from("\tExpected:\n\t\t\"foobar\"\n\tnot to match regex:\n\t\t\"foo.*\"")
7876
);
7977
}
80-
81-
#[test]
82-
fn match_regex_should_construct_a_match_regex_matcher() {
83-
expect(&"foobar").to(match_regex("foo.*"))
84-
}
8578
}

0 commit comments

Comments
 (0)