Last Updated: February 25, 2016
·
3.929K
· iwein

Use pendingUntilFixed to disable specs temporarily

A simple but undervalued feature of specs2 is pendingUntilFixed. Many people comment out important parts of their tests temporarily and sometimes litter them with TODO's.

It's perfectly reasonable to disable a test at some point. Either because you've broken it during a larger refactoring and want to get back at it later, or you simply don't have the time to dig into the reasons for it failing. If you comment out or change code inside the test this invites code rot and you'll not be reminded. Not so with pendingUntilFixed. Try it:

"pend until fixed" in {
    true === false
}.pendingUntilFixed

This will not break the build, just show one test as pending. It WILL actually run the test each time. And now comes the good part.

"pend until fixed" in {
  true === true
}.pendingUntilFixed

Will fail the build with a really nice message.

[error] x pend until fixed
[error]    Fixed now, you should remove the 'pendingUntilFixed' marker 

This avoids code rot because once you fix the test, you can reinstate the original test logic, just by removing that method. Your build will remind you as soon as you've reached this point.

Never ever disable your specs2 tests any other way. It makes a world of difference.