There is nothing special about this, you basically just have tests that look like actor samples, but use specs2 test syntax instead. If you want to use akka verification utilities, you will have to add an explicit dependency on it from the build.sbt file
libraryDependencies ++= Seq( "com.typesafe.akka" %% "akka-testkit" % "2.2.0" % "test" )
Then there is nothing special, except that you cannot inherit TestKit in a test class, since Specification is also a class and there are name classes. This is an example of how you can use custom Scope to use TestKit:
import org.specs2.specification.Scope class ActorSpec extends Specification { class Actors extends TestKit(ActorSystem("test")) with Scope "My actor" should { "do something" in new Actors { val actor = system.actorOf(Props[SomeActor]) val probe = TestProbe() actor.tell("Ping", probe.ref) probe.expectMsg("Pong") } "do something else" in new Actors { new WithApplication { val actor = system.actorOf(Props[SomeActorThatDependsOnApplication]) val probe = TestProbe() actor.tell("Ping", probe.ref) probe.expectMsg("Pong") }} } }
johanandren
source share