Scalatest and SprayIO fails

391 views Asked by At

I have problem with my test suite. No matter what I do I always get the same error message Request was not handled.

This is my test suite:

class EventsServiceSpec extends FlatSpec with ScalatestRouteTest with EventsService with Matchers {
  def actorRefFactory = system

  behavior of "Events service"

  it should "list all events" in {
    Get("events") ~> eventsRoute ~> check {
      status should equal (StatusCodes.OK)
    }
  }
}

Here are my routes for that service:

trait EventsService extends HttpService {
  val eventsRoute =
    path("events") {
      get {
        complete(StatusCodes.OK)
      } ~
      post {
        entity(as[Event]) { event =>
          complete(StatusCodes.OK)
        }
      }
    }
}

I have no idea what is wrong and I don't want to use another test framework. Because most of examples with tests in spray are written in Spec2. Maybe I'm missing something.

1

There are 1 answers

1
Gangstead On BEST ANSWER

I'm using Specs2 and I do tests with some different traits. Using your classes my tests look like this:

class EventsServiceSpecTest extends SpecificationWithJUnit with Specs2RouteTest with EventsService {

  "Events Service" should {

    "list all events" in {      
      Get("events") ~> eventsRoute ~> check {
        status === StatusCodes.OK
      }
    }
  }
}

The only other thing I can think is that your path might need to be "/events" instead of "events"