summaryrefslogtreecommitdiff
path: root/examples/automock.rs
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2023-03-26 16:30:19 +0200
committerHampusM <hampus@hampusmat.com>2023-03-26 16:37:54 +0200
commit7f9294869afd07e096e73a45e6a101b8970a0e6e (patch)
tree90705756cbd50fb81c964812717738109379fbbb /examples/automock.rs
parent9233c481d61271ee24b97fcb1820b459810e074c (diff)
feat: add automock attribute
Diffstat (limited to 'examples/automock.rs')
-rw-r--r--examples/automock.rs31
1 files changed, 31 insertions, 0 deletions
diff --git a/examples/automock.rs b/examples/automock.rs
new file mode 100644
index 0000000..c8725ce
--- /dev/null
+++ b/examples/automock.rs
@@ -0,0 +1,31 @@
+use cool_trais::Foo;
+use ridicule::predicate::{always, eq};
+
+use crate::cool_trais::MockFoo;
+
+mod cool_trais
+{
+ use ridicule::automock;
+
+ #[automock]
+ pub trait Foo
+ {
+ fn bar<Something>(&self, num: u128, text: &str) -> Something;
+ }
+}
+
+fn main()
+{
+ let mut mock_foo = MockFoo::new();
+
+ mock_foo
+ .expect_bar()
+ .with(eq(1234), always())
+ .returning(|_, num, text| {
+ println!("bar was called with {num} and '{text}'");
+
+ 9.36f32
+ });
+
+ mock_foo.bar::<f32>(1234, "Hello");
+}