1

I have following test in spray-testkit with scalatest and I do not understand why test passes every time despite the actual status.

import akka.actor._
import akka.event.LoggingReceive
import akka.testkit.TestProbe
import com.ss.rg.service.ad.AdImporterServiceActor.{GetImportStatus, StatusOfImport}
import org.scalatest.{MustMatchers, WordSpecLike}
import spray.http._
import spray.testkit.ScalatestRouteTest


class AdServiceApiTest extends WordSpecLike with MustMatchers with ScalatestRouteTest {

  "AdService REST api " must {
    "POST for import with mandatory parameters should be processed" in {
      val p = TestProbe()
      val addressServiceMock = system.actorOf(Props(classOf[AdServiceActorMock], p.ref))

      Post("/service/ad/import?adId=1") ~> new AdServiceApi(addressServiceMock).route ~> check {
        handled must be(true)

//        rejections must have size 1
        response.status === StatusCodes.NotAcceptable
      }
    }
  }

Test passes even though that status should be different and when I made the test failed for obvious reason like rejection ... the error msg is follows:

Request was not rejected, response was HttpResponse(202 Accepted,HttpEntity(text/plain; charset=UTF-8,The request has been accepted for processing, but the processing has not been completed.),List(),HTTP/1.1)
org.scalatest.exceptions.TestFailedException: Request was not rejected, response was HttpResponse(202 Accepted,HttpEntity(text/plain; charset=UTF-8,The request has been accepted for processing, but the processing has not been completed.),List(),HTTP/1.1)
    at spray.testkit.ScalatestInterface$class.failTest(ScalatestInterface.scala:25)

Seems that I am missing some important concept here.

Could someone please clarify?

UPDATE: Following works correctly

status must equal(StatusCodes.Accepted)
4

1 に答える 1

0

===十分ではありません。あなたは書く必要があります

status should === (StatusCodes.NotAcceptable)

また

assert(status === StatusCodes.NotAcceptable)
于 2015-03-16T18:06:14.340 に答える