How to not bind to localhost with ScalatestRouteTest

Viewed 430

I want to test routes with ScalatestRouteTest as follows:

trait MyRoutes extends Directives {

  self: Api with ExecutionContextProvider =>

  val myRoutes: Route =
    pathPrefix("api") {
      path("") {
        (get & entity(as[MyState])) {
          request => {
            complete(doSomething(request.operation))
          }
        }
      }
    }
  }
}


class RoutesSpec extends WordSpecLike with Api with ScalatestRouteTest 
  with Matchers with MyRoutes with MockitoSugar {

  "The Routes" should {

    "return status code success" in {
      Get() ~> myRoutes ~> check {
        status shouldEqual StatusCodes.Success
      }
    }
  }
}

When running the test I get the runtime error:

Could not run test MyRoutesSpec: org.jboss.netty.channel.ChannelException: Failed to bind to: /127.0.0.1:2552

I don't want to bind to the localhost. How can this be accomplished?

1 Answers
Related