Partial Stubs

Learn about partial stubs, stubs classes, and multiple partial stubs.

We might use a full double object to stand in for an entire object unavailable or prohibitively expensive to create or call in the test environment. We can also take advantage of how Ruby allows us to open up existing classes and objects to add or override methods. It’s easy to take a “real” object and stub out only the methods we need. This is extraordinarily useful when it comes to actual uses of stub objects.

In RSpec, partial stubs are managed with the allow method:

Get hands-on with 1200+ tech skills courses.