I wanted to stub out a method with predetermined values i.e. allow(user).speak.then_return('blah'), but also wanted to verify that the method was called. Using allow(user).speak.then_return('blah').exactly(2).times sets an upper bound on the stubs, but NOT a lower bound. The docs should indicate that you are able to use then_return on expects
To clarify - reading over the docs you get the impression that the canonical pattern would be to:
Some pain points I had on learning the doubles API that in my opinion, the documentation could be improved with:
expects
takes precedence overallow
(i.e.expects
will delete stubs that you created withallow
- both previous and subsequent) https://github.com/uber/doubles/blob/master/test/expect_test.py#L89 - maybe another entry to the FAQ section?allow(user).speak.then_return('blah')
, but also wanted to verify that the method was called. Usingallow(user).speak.then_return('blah').exactly(2).times
sets an upper bound on the stubs, but NOT a lower bound. The docs should indicate that you are able to usethen_return
onexpects
To clarify - reading over the docs you get the impression that the canonical pattern would be to:
Which not only doesn't work, but actually wipes out the stub you created via the first
allow
. Instead, the docs should show this: