Origins: Pure, Partial, and Verifying Doubles

Now that we’ve seen the different usage modes of test doubles, let’s look at where they come from.

Pure Doubles

All of the test doubles you’ve written so far in this chapter are pure doubles: they’re purpose-built by rspec-mocks and consist entirely of behavior you add to them. You can pass them into your project code just as if they were the real thing.

Pure doubles are flexible and easy to get started with. They’re best for testing code where you can pass in dependencies. Unfortunately, real-world projects are not always so tester-friendly, and you’ll need to turn to more powerful techniques.

Partial Doubles

Sometimes, the code you’re testing doesn’t give you an easy way to inject dependencies. ...

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

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.