Update documentation for expects
Opened this issue · 0 comments
cozos commented
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?- 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. 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:
# Causes nonintuitive behaviour.
allow(user).speak.then_return('blah')
expect(user).speak.exactly(2).times
Which not only doesn't work, but actually wipes out the stub you created via the first allow
. Instead, the docs should show this:
# What we actually wanted.
expect(user).speak.then_return('blah').exactly(2).times