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

Types of Test Doubles

When we first introduced test doubles, we hinted that there are different names for doubles—mocks, spies, and so on. But we glossed over some of the differences. Let’s take a closer look now.

There are a couple of different ways to think about a test double. One is the usage mode of the double—that is, what you’re using it for and what you’re expecting it to do. The other thing to consider is how the double is created. We’ll call this the double’s origin.

Here are the usage modes we’ll be talking about in this chapter:

Stub

Returns canned responses, avoiding any meaningful computation or I/O

Mock

Expects specific messages; will raise an error if it doesn’t receive them by the end of the example

Null Object

A benign test ...

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