etorreborre/specs2 — pull request #265 by Kornel (2014-05-23 07:26:14+00:00)
Title: Some exceptions do not contain a message

E.g. InvocationTargetException thrown when a class cannot be instantiated
does not contain a message, resulting in a NPE exception in specs,
making the stacktrace useless.

java.lang.Exception: Could not instantiate class XSpec: null

for the test

import org.specs2.mutable.Specification

class XSpec extends Specification {

val tested = new TestedComponent

"A spec" should {
"not fail with NPE" in {
success
}
}

}

case class MyException(message: String) extends
RuntimeException(message)

class TestedComponent {

val value = {
// This causes a InvocationTargetException with a null message,
// resulting in the stack trace from specs:
// java.lang.Exception: Could not instantiate class XSpec: null
if (1 == 1) throw new MyException("Oops")
"Oops"
}
}