scala - Spray rejections is not converted to status code? -


i following spray manual here. put gather pretty simple test

class atoimportserviceapitest extends wordspeclike mustmatchers scalatestroutetest {    "atoimportservice" must {     "return http status 401 unauhorized when accessing withou basic auth" in {       post("/ato/v1/orders/updatestatus") ~>new atoimportserviceapi().route ~> check {         handled must be(false)         rejections must have size 1         status === statuscodes.unauthorized       }     }   } } 

i calling route contains authorized directive. expect rejection transformed http status code. not happening here , test failing.

request rejected list(authenticationfailedrejection(credentialsmissing,list(www-authenticate: basic realm="bd ato import api"))) scalatestfailurelocation: spray.testkit.routetest$class @ (routetest.scala:74) org.scalatest.exceptions.testfailedexception: request rejected list(authenticationfailedrejection(credentialsmissing,list(www-authenticate: basic realm="bd ato import api")))     @ spray.testkit.scalatestinterface$class.failtest(scalatestinterface.scala:25) 

am missing important concept here?

you need "seal route" see actual status codes. sealing route means default rejection , exception handlers used handle far unhandled rejections , exceptions. automatically done when using runroute in service isn't done automatically in testkit allow check rejections directly.

using spray-testkit need wrap route sealroute(...) explained here: http://spray.io/documentation/1.2.2/spray-testkit/#sealing-routes

try this:

post("/ato/v1/orders/updatestatus") ~> sealroute(new atoimportserviceapi().route) ~> check { // ... 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -