Search code examples
scalamatcherspecs2

How to show custom failure message in Specs2 (Scala)?


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?


Solution

  • 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")