Most of the specifications we write are known up front because this is precisely what guides the construction of our systems. But sometimes data comes first and drives what we can do with the system. For example we want to check that:
More precisely we want to create one example for 1.
and if it succeeds, create as many examples as there are links in 2.
. This can be done with the org.specs2.specification.dsl.Online
trait and the continueWith
method:
// fill in the definitions below
object Wikipedia:
def getPages(searchTerm: String): Seq[Page] = ???
trait Page:
def getLinks: Seq[HtmlLink] = ???
trait HtmlLink:
def contains(name: String): Boolean = ???
def getName: String = ???
def getLinkedPage: Page = ???
In the specification above, if we succeed in checking each BDD page then we continue with the creation of individual examples for each encountered link.