Mocks, stubs, and doubles
The word
mock is generic. Often the words stub, fake, and double are used to mean the same thing. To be precise, we could make a distinction between mocks and stubs. A mock is a fake object that stands in the place of an actual object. A stub is a fake method that is executed in place of an actual method. In practice, the terms are used interchangeably. In fact, our Object#mock method should have been named Object#stub if we were being consistent.
RSpec uses the method double to handle mocking. This is aliased as stub and mock, which can be confusing, but these aliases are both deprecated, so you shouldn't use them. There is also a method called spy, which is a convenience method based on double that I encourage you ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access