Skip to content

Commit 4c499a9

Browse files
committed
test: tested valid emails with multiple emails
1 parent 02d6f24 commit 4c499a9

File tree

3 files changed

+54
-5
lines changed

3 files changed

+54
-5
lines changed

Cargo.lock

Lines changed: 35 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ fake = "2.6.1"
3535
reqwest = "0.11.18"
3636
once_cell = "1"
3737
claim = "0.5"
38+
quickcheck = "1.0.3"
39+
quickcheck_macros = "1.0.0"
40+
rand = "0.8.5"
3841

3942
[profile.release]
4043
strip = true

src/domain/subscriber_email.rs

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ mod tests {
2424
use claim::{assert_err, assert_ok};
2525
use fake::faker::internet::en::SafeEmail;
2626
use fake::Fake;
27+
use quickcheck::Gen;
28+
use rand::{rngs::StdRng, SeedableRng};
2729

2830
#[test]
2931
fn empty_string_is_rejected() {
@@ -61,11 +63,20 @@ mod tests {
6163
assert_err!(SubscriberEmail::parse(email));
6264
}
6365

64-
#[test]
65-
fn valid_emails_are_parsed_successfully() {
66-
let email = SafeEmail().fake();
67-
println!("{}", email);
68-
assert_ok!(SubscriberEmail::parse(email));
66+
#[derive(Debug, Clone)]
67+
struct ValidEmailFixture(pub String);
68+
69+
impl quickcheck::Arbitrary for ValidEmailFixture {
70+
fn arbitrary(g: &mut Gen) -> Self {
71+
let mut rng = StdRng::seed_from_u64(u64::arbitrary(g));
72+
let email = SafeEmail().fake_with_rng(&mut rng);
73+
Self(email)
74+
}
6975
}
7076

77+
#[quickcheck_macros::quickcheck]
78+
fn valid_emails_are_parsed_successfully(valid_email: ValidEmailFixture) -> bool {
79+
let ValidEmailFixture(email) = valid_email;
80+
SubscriberEmail::parse(email).is_ok()
81+
}
7182
}

0 commit comments

Comments
 (0)