kriomant/mockers

reference arguments to calls

nikodemus opened this issue · 1 comments

It seems to me that currently one cannot write scenarios that make assertions about reference arguments.

Could there be a ref(s) matcher that compares the received reference to an owned object?

#[mocked]
trait Foo {
    fn bar(&self, x: &String);
}

#[test]
fn test_foo() {
    let scenario = Scenario::new();
    let foo = scenario.create_mock_for::<Foo>();
    let s = String::from("test");
    // Error: 's' does not live long enough
    scenario.expect(foo.bar_call(&s).and_return(()));
    foo.bar(&s);
}

Thanks for raising this issue. Proper support for references will be added soon.
Right now you can use check!:

scenario.expect(foo.bar_call(check!(|s| *s == "test")).and_return(()));