Daryl Odnert
Daryl Odnert

Reputation: 532

Is there syntax for adding a clue to ScalaTest matchers?

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

Upvotes: 9

Views: 1442

Answers (1)

gzm0
gzm0

Reputation: 14842

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.

Upvotes: 18

Related Questions