I'm working with ScalaMock and ScalaTest to put together some unit tests. I want to use the ScalaMock's expectation syntax to confirm that the service I'm working on passes along acceptable Json to a mocked resource. In this case acceptable means some internal fields can be different, so I've written a custom function to determine whether the fields I care about match. The problem with this is that it produces relatively unhelpful logging when the expectations are not fulfilled. The expectations set as in:
(mockedResource.doAThing(_: Json)(_: SomeImplicitThing))
.expects(
where(
jsonSimilarAndImplicitEqual(
expectedJson,
anInstanceOfImplicitThing
)(_, _)
)
)
Produce the following logging on failure:
- should forward acceptable Json to the mockedResource
Unsatisfied expectation:
Expected:
[info] inAnyOrder {
[info] <mock-1> MockedResource.doAThing<function1> once (never called - UNSATISFIED)
[info] }
I'd like to be able to provide some custom logging function to describe why jsonSimilarAndImplicitEqual
evaluated to false in a sensible place. I was hoping an inAnyOrderWithLogging
block would prove sufficient, but it turns out I can't even use this construct, since it is not supported for AsyncMockFactory.