February 2018
Intermediate to advanced
406 pages
9h 52m
English
RSpec allows a number of different annotations to the expectation part of declaring a test double. You can specify more complex return values or a variety of arguments to the stubbed method.
A couple of advanced usages of returns might be valuable now and again. If you’ve multiple return values specified, the stubbed method returns one at a time:
| | it "stubs with multiple return values" do |
| | task = Task.new |
| | allow(task).to receive(:size).and_return(1, 2) |
| | assert_equal(1, task.size) |
| | assert_equal(2, task.size) |
| | assert_equal(2, task.size) |
| | end |
The return values of the stubbed method walk through the values passed to and_return. Note that the values ...