您可以通过实现自己的Diffs
trait 来控制如何处理差异:
import org.specs2._
import main._
class MyDiffs extends Diffs {
/** @return true if the differences must be shown */
def show: Boolean = true
/** @return true if the differences must be shown for 2 different strings */
def show(expected: String, actual: String): Boolean =
expected.size + actual.size < 100
/** @return the diffs */
def showDiffs(expected: String, actual: String): (String, String) =
(expected.take(10).mkString, actual.take(10).mkString)
/** @return true if the full strings must also be shown */
def showFull: Boolean = false
/** this method is not used and will be removed from the trait in a next release */
def separators: String = ""
}
class s extends Specification { def is =
args.report(diffs = new MyDiffs)^
"test" ! {
"abcdefghijklmnopqrstu" must_== "abcdefghijklmnopqrstuvwxyz"
}
}
x test
'abcdefghijklmnopqrstu' is not equal to 'abcdefghijklmnopqrstuvwxyz' (<console>:47)
Expected: qrstuvwxyz
Actual: lmnopqrstu