From ad2a6d1dc517407939ed022bba9f3352efc678ce Mon Sep 17 00:00:00 2001 From: HampusM Date: Sun, 19 Mar 2023 16:29:23 +0100 Subject: feat: add call count expectations to expectations --- examples/generic_method.rs | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) (limited to 'examples/generic_method.rs') diff --git a/examples/generic_method.rs b/examples/generic_method.rs index 8dc4650..995c67d 100644 --- a/examples/generic_method.rs +++ b/examples/generic_method.rs @@ -1,8 +1,10 @@ +use std::fmt::Display; + use ridicule::mock; trait Foo { - fn bar(&self, num: u128) -> Baz; + fn bar(&self, num: u128) -> Baz; } mock! { @@ -10,7 +12,7 @@ mock! { impl Foo for MockFoo { - fn bar(&self, num: u128) -> Baz; + fn bar(&self, num: u128) -> Baz; } } @@ -18,11 +20,14 @@ 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() + .returning(|_me, num| { + println!("bar was called with {num}"); - "Hello".to_string() - }); + "Hello".to_string() + }) + .times(3); mock_foo.expect_bar().returning(|_me, num| { println!("bar was called with {num}"); @@ -31,6 +36,11 @@ fn main() }); assert_eq!(mock_foo.bar::(123), "Hello".to_string()); + assert_eq!(mock_foo.bar::(123), "Hello".to_string()); + assert_eq!(mock_foo.bar::(123), "Hello".to_string()); + + // Would panic + // mock_foo.bar::(123); assert_eq!(mock_foo.bar::(456), 128); } -- cgit v1.2.3-18-g5258