I'm trying to test an Actor A
inside my Play 2.4 application with Scaldi. This actor is calling injectActorRef[B]
that I want to mock with a TestKit.TestProbe
.
Inside my specs2, I would like to be able to retrieve the probe for mocked B
while providing the corresponding TestKit.TestProbe.ref to actor A
.
I would like to do something like this :
implicit val inj = (new TestModule(){
bind[TestProbe] identifiedBy 'probeForB to TestProbe()
bind[B] to inject[TestProbe]('probeForB).ref
}).injector
inject[TestProbe]('probeForB).expectMsgType[] must ...
The issue is that the ref is an ActorRef
and therefore does not match the expected B
type.
Is there a clean way to do that ?
Can we specify an ActorRef to be returned by injectActorRef[B]
?
I ended up overriding the bind for Actor A
.
val probeForB = TestProbe()
implicit val inj = (new Module() {
bind[A] to new A() {
override def injectB(): ActorRef = probeForB.ref
}
}).injector