fmonniot / scala3mock

Mocking framework for Scala 3
https://francois.monniot.eu/scala3mock
Other
21 stars 2 forks source link

Better mock names #24

Closed fmonniot closed 10 months ago

fmonniot commented 10 months ago

This address and fix https://github.com/fmonniot/scala3mock/issues/8.

We are doing it a bit differently from the original ScalaMock. They have an increasing counter stored in the mock counter. This is great to distinguish mocks of the same class based on their declaration order, but you still have to track down which one you defined first.

Instead what we are doing here is to rely on the position within the source code where the mock was defined. This is a bit more verbose, but instantanely inform the user on which mock they are looking at. An example of such error is as follow:

Unexpected call: <ErrorReportingTest.scala#L99> TestTrait.oneParamMethod(3)

Expected:
inAnyOrder {
  <ErrorReportingTest.scala#L92> OuterTestTrait.noParamMethod() twice (called once - UNSATISFIED)
  <ErrorReportingTest.scala#L99> TestTrait.polymorphicMethod(List(1)) once (never called - UNSATISFIED)
}

Actual:
  <ErrorReportingTest.scala#L92> OuterTestTrait.noParamMethod()
  <ErrorReportingTest.scala#L99> TestTrait.oneParamMethod(3)
fmonniot commented 10 months ago

I still have to look at adding type parameters next to the method name being invoked, although I'm wondering if it's actually worth the extra effort or not šŸ¤”

fmonniot commented 10 months ago

It turned out to not be too complex to add, although IĀ did assume that there can only be one type parameters list and it has to be at the beginning. Time will tell if that's true (or will stay true).