diff options
author | HampusM <hampus@hampusmat.com> | 2023-03-25 11:58:16 +0100 |
---|---|---|
committer | HampusM <hampus@hampusmat.com> | 2023-03-25 11:58:16 +0100 |
commit | aef63bfecb7731c0307cc65eab0b9a06b8a7363d (patch) | |
tree | 8455d54be4fd4008ac593fae5e9e9608198a61b5 /examples/basic.rs | |
parent | 96a13690f8552386bb183ebc01418774047ebbfc (diff) |
feat: add argument matching
Diffstat (limited to 'examples/basic.rs')
-rw-r--r-- | examples/basic.rs | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/examples/basic.rs b/examples/basic.rs index a157413..01688f5 100644 --- a/examples/basic.rs +++ b/examples/basic.rs @@ -1,8 +1,9 @@ use ridicule::mock; +use ridicule::predicate::{always, eq}; -trait Foo: Sized +trait Foo { - fn bar(&self, num: u128) -> &Self; + fn bar(&self, num: u128, text: &str); } mock! { @@ -10,7 +11,7 @@ mock! { impl Foo for MockFoo { - fn bar(&self, num: u128) -> &Self; + fn bar(&self, num: u128, text: &str); } } @@ -18,11 +19,12 @@ fn main() { let mut mock_foo = MockFoo::new(); - mock_foo.expect_bar().returning(|me, num| { - println!("bar was called with {num}"); + mock_foo + .expect_bar() + .with(eq(1234), always()) + .returning(|_, num, text| { + println!("bar was called with {num} and '{text}'"); + }); - me - }); - - mock_foo.bar(123); + mock_foo.bar(1234, "Hello"); } |