I'm using mockall to produce tests of my class. The problem I'm running into is that if I just
let mock_listener = MockStateChangeListener::new();
let expected_state = StateDetails { ... };
mock_listener
.expect_on_state_change()
.times(1)
.with(eq(expected_state))
.returning(|_| ());
Then when if the supplied struct is different I get no information about what was different. To fix this I wrote my own comparison method and writes debug printouts, but that's obviously not ideal. Is there a better way to do this so that I get useful debug outputs? Like an equality predicate that can output useful struct diffs?
thread 'listener_test' (30296616) panicked at tests/common/mod.rs:34:1:
MockStateChangeListener::on_state_change(StateDetails { id: "...", name: "test-3of5", info: [...] }): No matching expectation found
It doesn't give what was expected, and it's really hard to parse where the failure came from. It would be really helpful if there were a struct equality predicate that could have debug info turned on when needed for what's wrong/different.
can't you just wrap an assert_eq!() as your predicate? is the panic message good enough for you? the rust test harness treats any panic inside a test case as a failure (unless #[should_panic] is used, of course), I feel like the mock predicate is almost redendent.
I see there's a function() predicate, you can just create a wrapper, something like this:
Unfortunately, in my particular test I'm expecting several calls to the callback, each with different params. I was hoping the sequencing in mockall would do the trick, but sadly it doesn't. So what I'm looking for is a comparison that tells me what's different so I can trace it back and figure out why the test failed.