没有
容易的
要做到这一点,你需要解构和重建一些东西
type RowResult = (Seq[String], Result)
val table =
"input" | "expectedResult" |
"123" ! 123 |
"0" ! 1 |
"0" ! 0
// get a Future containing all rows and results
val results: Future[List[RowResult]] = table.rows.toList.traverseU { row =>
getDataForInput(row.t1).map { i =>
(row.showCells, (i must beEqualTo(row.t2)).toResult)
}
}
// check the results
results must beSuccessfulTable(table.titles).await
这使用了一个自定义的匹配器,这会使表格显示得更不美观
// the TextTable does an even display of columns
import org.specs2.text.TextTable
def beSuccessfulTable(titles: Seq[String]): Matcher[List[RowResult]] = { values: List[RowResult] =>
val overallSuccess = values.map(_._2).reduce(_ and _).isSuccess
val headers = if (overallSuccess) titles else Seq("")++titles++Seq("")
val table = TextTable(headers, values.map(resultLine.tupled))
(overallSuccess, table.show)
}
// helper method
def resultLine = (line: Seq[String], result: Result) => {
val message = if (result.isSuccess) "" else result.message
result.status +: line :+ message
}