9

Is there an idiom for adding a clue to a ScalaTest matcher such that the clue will become part of the assertion failure? I know that I can currently write a ScalaTest assertion like this:

withClue("expecting a header row and 3 rows of data") {
  rowCount should equal(4)
}

Is this the only syntax for adding the clue to the assertion? It would be nice to be able write an assertion to look something like this:

rowCount should equal(4) because("expecting a header row and 3 rows of data")
Daryl Odnert
  • 522
  • 3
  • 15

1 Answers1

18

If you mixin AppendedClues you can write the withClue as a suffix:

class TestSuite extends FlatSpec with Matchers with AppendedClues {
  3 should equal(4) withClue("expecting a header row and 3 rows of data")
}

Also works without parens of course.

gzm0
  • 14,752
  • 1
  • 36
  • 64