Mock Expectations

Learn about mock object expectations and validations.

Mock objects expectations

A mock object retains the stub’s basic idea, which is to return a specified value without actually calling a live method,and adds the requirement that the specified method must be called during the test. A mock is like a stub with an attitude, demanding that its parameters be matched in the test or else we get a test failure.

Expectations mocking

In RSpec, we use the expect method to create mock expectations. This can be applied to full or partial doubles:

Get hands-on with 1400+ tech skills courses.