O'Reilly logo

Effective Testing with RSpec 3 by Myron Marston, Ian Dees

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required