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

Using Partial Doubles Effectively

Partial doubles are really easy to use: just stub or expect a message on any object! However, we said in Partial Doubles that we consider their usage to be a code smell. We’d like to flesh that statement out a bit now.

Most unit tests involve a mixture of two types of objects:

  • Real objects: typically the subject of the example
  • Fake objects: collaborating test doubles used to construct an environment for the test subject

Partial doubles don’t fit neatly in this hierarchy. They are partially real and partially fake. Are they part of what you are testing or part of the environment you are constructing? When an object’s roles are unclear, your tests can be harder to reason about.

We prefer not to mix these roles ...

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