Based off iredelmeier's initial mock implementation.
Double lets you mock Trait
implementations so that you can track function call arguments and set return values or overrides functions at test time.
Here's a quick example:
```rust extern crate double;
use double::Double;
trait Foo: Clone { fn expensive_fn(&self, x: i64, y: i64) -> i64; }
struct DoubleFoo { pub expensive_fn: Double<(i64, i64), i64>, }
impl Foo for DoubleFoo { fn expensivefn(&self, x: i64, y: i64) -> i64 { self.expensivefn.call((x + 10, y)) } }
fn doubleexpensivefn
fn doublesreturnvalue() { let mock = DoubleFoo { expensive_fn: Double::default() };
mock.expensive_fn.return_value(1000);
assert_eq!(double_expensive_fn(&mock, 1, 2), 2000);
}
fn usescorrectargs() { let mock = DoubleFoo { expensive_fn: Double::default() };
assert!(!mock.expensive_fn.called());
double_expensive_fn(&mock, 1, 2);
assert_eq!(mock.expensive_fn.num_calls(), 1);
assert!(mock.expensive_fn.called_with((11, 2)));
} ```
More examples are available in the examples directory.
This library is based off iredelmeier's initial mocking implementation. Massive thanks to her implementation for inpsiring me to work on this. The repo for her library can be found here.
If you're interested in testing, check out her other repositories too!