所以你可以通过两种方式做到这一点:
Specs2 允许您使用字符串作为片段的可选参数,因此您可以执行以下操作:
class MySpec extends Specification {
"Something" should {
"do something" in {
fragmentName: String =>
println(fragmentName) //prints do something
ok
}
"do something else" in {
fragmentName: String =>
println(fragmentName) //prints do something else
ok
}
}
}
还有一种 hacky 方式(我先玩了这个,但就是不能把它扔掉):
更新 这是@Eric
建议的“更好”的 hacky 版本
class MySpec extends Specification {
"Something" should {
"do something" in {
val fragmentName = is.examples(0).desc
println(fragmentName) //prints do something
ok
}
"do something else" in {
val fragmentName = is.examples(1).desc
println(fragmentName) //prints do something else
ok
}
}
}