If you are just a regular villain, your henchmen are close to you. You have recruited them personally, know what they
can do, and call each one of them by their name… Well, not really, because you don't care about their names. But you
don't have any issues letting them know what you want from them, because they are always around you. Those times are
long gone and deeply missed.
In the previous article, I explained how to use a test double to replace a File instance and control the behavior
required by a function that reads from it. With the test double in place, I was able not only to return what I needed
for the scenarios where I needed reading, but also to produce errors that allowed me to test the not-so-happy path.
I got some concerned comments pointing out that the test code wasn't reading, which was an essential part of what we
were testing. I agree that the test code isn't actually reading. It isn't, and that is on purpose. On the one hand,
reading isn't an essential part of what we are testing. On the contrary, File is a dependency of the
are_there_vulnerable_locations() method, and, as with any other dependency, it can be replaced by a test double. The
code isn't making it easy to inject the dependency, because the File instance is created inside of the method –and as
you may already know, every time you create an instance inside of your code, a kitten is killed. But I applied
what I had already explained to replace dependencies using the namespace. On the other hand, we gain additional
benefits by using a test double. I mentioned that performance is much better, but you can only notice the difference
with a large test suite. However, it is also important that the test double can easily reproduce File behaviors that
would require some work when you are actually interacting with the filesystem. For example, opening the file for
reading successfully and then failing to read from it right away.