Spray testkit with Cookies

188 views
Skip to first unread message

Sam Grönblom

unread,
Feb 25, 2015, 3:38:23 AM2/25/15
to spray...@googlegroups.com
I'm trying to test a route that uses optionalCookie. I tried using:

val cookieHeader: Cookie = HttpHeaders.Cookie(HttpCookie("uid", "12345abcde", None, None, None, None, false, true, None))
Get(URL) ~> addHeader(Cookie) ~> ROUTE ~> check { assertions }

But unfortunately the optionalCookie("uid") gives me None each time. Haven't dug too deep into what Spray is doing when it's parsing Cookies, but maybe I need to set the other cookie parameters correctly?

Age Mooij

unread,
Feb 25, 2015, 4:42:28 AM2/25/15
to spray...@googlegroups.com
Are you setting the cookie back to the response from your routes under test? In this test you add a request cookie but in your assertions I assume you are checking for response cookies (i.e. Set-Cookie headers). 

Your route would normally be responsible for extracting the cookie from the request and (optionally) setting it back (i.e. overwriting it) in the response.

Have a look at the docs for the setCookie directive, which also show how to test the response:


Hope this helps
Age


--
You received this message because you are subscribed to the Google Groups "spray.io User List" group.
To unsubscribe from this group and stop receiving emails from it, send an email to spray-user+...@googlegroups.com.
Visit this group at http://groups.google.com/group/spray-user.
To view this discussion on the web visit https://groups.google.com/d/msgid/spray-user/467f066b-1ce6-4ebf-8ad7-95e038d61bdf%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages