We cover:

  • The importance of carefully constructing an environment for each spec
  • How to provide test doubles to the code you’re testing
  • What the most common pitfalls are and how to avoid them
  • How to improve your code by applying design feedback from your test doubles

Chapter 15Using Test Doubles Effectively

Over the previous two chapters, you’ve tried out mocks, stubs, spies, and null objects. You’ve learned which situations each is best for. You’ve also seen how to configure their behavior, and how to check that a test double is called correctly.

Now we’d like to talk about the trade-offs. Although we frequently use doubles in our specs, we’ll be the first to acknowledge that doing so incurs some risk. Here are some of the problems you can run ...

Get Effective Testing with RSpec 3 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.