11

For example, for code like this:

myNum must beEqualTo("SOME INTERESTING TEXT")

The message will be like the following:

java.lang.Exception: ArrayBuffer() doesn't have size 1 but size 0

Is there an elegant way to get customised message displayed here?

Johnny
  • 14,397
  • 15
  • 77
  • 118

1 Answers1

22

First you can name value you're testing.

myNum aka "meaningful name" must_== expectedValue

You can also overwrite the full message.

(myNum must_== expectedValue).setMessage("Full failure message")
cchantep
  • 9,118
  • 3
  • 30
  • 41
  • 1
    This doesn't seem to work for "mutable" expectations. See http://etorreborre.github.io/specs2/guide/SPECS2-3.0/org.specs2.guide.ExpectationDescription.html for more options. – Rich Oct 28 '15 at 11:45
  • It is quite maddening that the above does not work for mutable expectations, and the link above does not work. This one has no information on the matter: https://etorreborre.github.io/specs2/guide/SPECS2-3.8.5/org.specs2.guide.ExpectationDescription.html – Scott Carey Jan 27 '17 at 02:12
  • Sadly, `aka` worked, but not `setMessage`. It compiled, but it didn't changed the error message. – Moebius Sep 05 '19 at 14:31
  • Looks like this `setMessage` sometimes does not work depending on the way you write your assertion: https://github.com/etorreborre/specs2/issues/832 – Somatik Jun 03 '20 at 08:13