Search code examples
scalaspecs2

Spec not failing on Mockito Matchers.any[FooException] matcher


In my spec, I expect the mock invocation msg.ctx.failWith(any[TimeoutException]).

Because failWith takes a Throwable, the type of the exception is not checked - even at runtime.

This nonsense passes:

there was one(msg.ctx).failWith(Matchers.any[ArrayIndexOfOutBoundsException])

Can I assert that the correct type of exception is passed?

I'm using Specs 2.3.13 (because it is a dependency of akka-test-kit)


Solution

  • This is not pretty but it works:

    there was one(m).failWith(beLike[Throwable] { case _: TimeoutException => ok })