uber / doubles

Test doubles for Python.
MIT License
164 stars 17 forks source link

mocks/expectations that do not call production method #122

Closed mehulkar closed 7 years ago

mehulkar commented 7 years ago

I would like to be able to set an expectation that shutil.copytree is called (or any other module that involves the outside system).

Right now, i can either stub using the method allow or expect it to be called using expect, but I can't see how to do both. I see from the docs that the purpose of a stub is to set a return value, but I would like to set an expectation that also stubs out the behavior. In rspec (ruby world) this is done like this:

expect(my_object).to receive(:some_method)
# and to actually call it:
expect(my_object).to receive(:some_method).and_call_original

Is this possible in this library?

toddsifleet commented 7 years ago

Not directly, but I think this will work:

 expect(my_object).some_method.and_return_result_of(my_object.some_method)

You can also do:

 def temp(*args, **kwargs):
     # do some stuff

 expect(my_object).some_method.and_return_result_of(temp)

http://doubles.readthedocs.io/en/latest/api.html?highlight=result_of#doubles.allowance.Allowance.and_return_result_of

mehulkar commented 7 years ago

ah, very nice. thank you!