Refactoring: Count the Contexts
Hi Folks,
Two posts in a week! How about that?
This post details a strategy called Count the Contexts.
This strategy is useful for spot-checking the actual test coverage of a method or class before beginning to refactor it. Code coverage tools are nice, but they can also give us a false sense of security. Along with automated tools, we need to understand the number of different paths execution might take through our code.
If we strive for complete coverage in a piece of code, we need to exercise all of those paths. Those paths may be hidden behind programming language features at times. This post helps uncover all of the places where language features may mask the complexity of the code at hand.
This post uses examples from tests (or “specs”) written in the RSpec framework in Ruby.
Special thanks to Alex Navasardyan, Ben Vinegar, Marc Köhlbrugge, Justin Duke, and Nathaniel Watts for providing feedback on early drafts of this post.
Have a good weekend!