Sometimes a test suite might need an assertion that is too specific to be included in the general repository. Not to worry, simply implement a function with the following signature (replace the bracketed parts and string values):

  1. func should<do-something>(actual interface{}, expected ...interface{}) string {
  2. if <some-important-condition-is-met(actual, expected)> {
  3. return "" // empty string means the assertion passed
  4. }
  5. return "<some descriptive message detailing why the assertion failed...>"
  6. }

Suppose I implemented the following assertion:

  1. func shouldScareGophersMoreThan(actual interface{}, expected ...interface{}) string {
  2. if actual == "BOO!" && expected[0] == "boo" {
  3. return ""
  4. }
  5. return "Ha! You'll have to get a lot friendlier with the capslock if you want to scare a gopher!"
  6. }

I can then make use of the assertion function when calling the So() method in the tests:

  1. Convey("All caps always makes text more meaningful", func() {
  2. So("BOO!", shouldScareGophersMoreThan, "boo")
  3. })

[[Next|Execution]]

If you haven’t figured out how already, it’s time to [[learn how to run your tests|Execution]].