6

I've got a Spray service that expects a POST with certain form fields filled out. I'm trying to work out how to create an appropriate POST in my test spec in order to test this.

What I have so far

  Post("/customer") ~> sealRoute(myRoute) ~> check {
    responseAs[String] must contain("Success message")
  }

Which does a POST to the /customer route, as expected. How do I add form fields to this?

Ren
  • 3,395
  • 2
  • 27
  • 46

1 Answers1

10

You can use the spray.http.FormData class:

Post("/customer", FormData(Seq("field1"->"value1", "field2"->"value2")) ~>
  sealRoute(myRoute) ~> check {
    responseAs[String] must contain("Success message")
  }
kong
  • 1,961
  • 16
  • 16
  • Doesn't compile with `could not find implicit value for parameter ta: MyControllerSpec.this.TildeArrow[spray.routing.RequestContext,Unit] Post("/customer", FormData(Seq("field1"->"value1", "field2"->"value2"))) ~> sealRoute(sso.route) ~> check {^` – Tvaroh Feb 25 '15 at 11:28
  • `Post("/", FormData(Map("foo" -> "bar"))) ~> route ~> check` works for me – Sergey Mar 09 '16 at 20:14