More Expectation Annotations
Explore how to enhance your automated tests in Rails by using advanced RSpec annotations for test doubles. Learn to stub methods with multiple return values, yield to blocks, call original methods, and fine-tune mocks using argument matching to create isolated and effective tests.
RSpec allows several different annotations to the expectation part of declaring a test double. We can specify more complex return values or a variety of arguments to the stubbed method.
Stubbing return values
A couple of advanced usages of returns may be valuable now and again. If we have multiple return values specified, the stubbed method returns one at a time (spec added on line 21):