In this episode, we quickly dive into the concept of higher order tests and how they can drastically simplify your test code. We take one of our existing tests and show how it can be refactored into a much more concise form using higher order chaining, which lets you remove the callback functions and just chain your testing methods directly. This not only makes your tests easier to read but also saves you a ton of time in the long run.
We compare the "old way" of writing tests with closures and the "higher order" way—basically chaining methods like post
, assertSessionHasErrors
, or get
and assertStatus
all in one line. You’ll see how super simple assertions (like checking a route returns a 200 status) can be written out in a single statement, instead of writing out a full test class and methods. It's a real game changer for basic tests!
We also touch on a small gotcha when chaining on higher order tests and hint that there’s a bit more to be aware of for things like assertDatabaseHas
. That’s coming up next, so stay tuned!