【发布时间】:2014-10-01 06:41:07
【问题描述】:
在这段代码 sn-p 中,SqlTypes.BinaryTypes 是 (String, Int) 元组的列表。
"process binary types" >> {
SqlTypes.BinaryTypes.foreach(sqlType => {
val label = sqlType._1
val value = sqlType._2
s"$label" in new ABinaryColumnHandler {
handler.canProcess(value) should beTrue
}
})
"for all of them" in new ABinaryColumnHandler {
handler should processTypes(SqlTypes.BinaryTypes)
}
}
第一部分,foreach 所在的位置,为列表的每个元素创建一个新示例,并运行简单测试。第二部分调用自定义匹配器:
def processTypes(typeList: List[(String, Int)]): Matcher[ColumnHandler] = (handler: ColumnHandler) => {
forall(typeList) { sqlType =>
val value = sqlType._2
handler.canProcess(value) should beTrue
}
}
如果没有在其后定义另一个示例,第一部分将无法运行,因为该 foreach 的返回是 Unit 而不是 Example 或 Fragment。我尝试了第二种方式,因为它看起来更简单,但我无法按照我想要的方式构造它的输出,就像这样(在 IntelliJ 中,但在 SBT 中看起来相似):
我真正想要的是 Specs2 在两种情况下都输出相同,或者更像
process binary types
for all of them
BINARY
VARBINARY
LONGBINARY
如何调整后一个示例的运行方式以输出我想要的方式?
【问题讨论】:
标签: scala intellij-idea specs2