0
我有一組規格,它們有重複的代碼。我一直使用不同的輸入調用相同的方法,並對結果進行相同的一組斷言。在二級函數中使用specs2匹配器
我想使用一個函數來減少重複,有點像下面的例子。有沒有辦法做到這一點?如果是這樣,是否有辦法做到這一點,以便我的斷言可以在整個函數體中混合,並且函數返回類型不必是匹配器?
"MyApp" should {
"do something" in {
tryOperation("large-one")
tryOperation("small-one")
tryOperation("another-one")
//...
}
}
def tryOperation(input: String): Result = {
val result = classUnderTest.operation(input)
result.foo must beEqualTo(bar)
result.length must beGreaterThan(0)
result
}