We cover:

  • How doubles can isolate your code from your dependencies
  • The differences between mocks, stubs, spies, and null objects
  • How to add test double behavior to an existing Ruby object
  • How to keep your doubles and your real objects in sync

Chapter 13Understanding Test Doubles

In movies, a stunt double stands in for an actor, absorbing a punch or a fall when the actor can’t or shouldn’t do so. In test frameworks like RSpec, a test double fulfills the same role. It stands in for another object during testing.

You’ve used this concept before, in Test Doubles: Mocks, Stubs, and Others. When you wrote your API unit specs, you treated the storage layer as if it were behaving exactly how you needed it to—even though that layer hadn’t been written ...

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.