2

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.

bkowalikpl
  • 817
  • 5
  • 11
  • 1
    Have you tried testing against this URI instead: `"/events"` ? The `path`/`pathPrefix` directives only match a path segment with a leading slash. The reason is that the URI of every incoming request is an absolute one and therefore always starts with a slash. – jrudolph May 20 '14 at 08:27

1 Answers1

1

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"

Gangstead
  • 4,152
  • 22
  • 35