mercredi 16 novembre 2016

Writing Given/Then/When specs with complex objects

I am trying to make use of GWT specs with full support, but the examples of its official documentation are a bit simple.

Searching in SO I found this question:

But it is too old (3 years) and I think the way of doing GWT in specs2 has changed.

So far I have this simple test:

class FlowCollectorSpec extends Specification
  with GWT
  with StandardRegexStepParsers { def is = s2"""

 Given a API route to get flows                                             ${apiCaller.start}
   Given an access to the API URL: http://ift.tt/2f3zUer
   When getting flow stats for a switch with id: 1
   Then status code should be: 200                                          ${apiCaller.end}
"""

  val anAPIUri = readAs(".*: (.*)$").and((s: String) => s)

  val apiCaller =
    Scenario("apiCaller").
      given(aString).
      given(anInt).
      when(anAPIUri) {case url :: dpid :: _ => FlowCollector.getSwitchFlows(dpid)}.
      andThen(anInt) {case expected :: actual :: _ => actual.code must_== expected}
}

How could I specify a complex object in a Given statement? something like this:

Given a Json response: ${jsonResponse}

Aucun commentaire:

Enregistrer un commentaire