Skip to content

Commit

Permalink
Document everlasting expectations
Browse files Browse the repository at this point in the history
  • Loading branch information
haarcuba committed Jun 1, 2023
1 parent c49259c commit 904111d
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
19 changes: 19 additions & 0 deletions docs/reference/scenarios_and_fake_objects.rst
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,25 @@ This demands that the fake is called with ``'b'`` only *after* it was called wit

The code in ``my_code()`` passes this test.

Of course you can still use the ``>>`` operator to specify return values for your expectation.

Everlasting Expectations
------------------------

Sometimes we don't want to test for a specific number of calls, but
we do want to make sure that a function call is of a particular form.

We can modify an ``.unordered()`` expectation with ``.everlasting()`` and
this essentially modifies the expectation to mean "this call is expected zero or more times, in any order".

Here's a small example

.. literalinclude:: test_everlasting.py
:linenos:
:emphasize-lines: 7,13-15,18,21-22

Of course you can still use the ``>>`` operator to specify return values for your expectation.


Context Manager Expectations
============================
Expand Down
22 changes: 22 additions & 0 deletions docs/reference/test_everlasting.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from testix import *

def test_unordered_expecation():
with Scenario() as s:
s.some_object('a')
s.some_object('b')
s.some_object('c').unordered().everlasting()

my_fake = Fake('some_object')
my_code(my_fake)

def my_code(x):
x('c')
x('c')
x('c')

x('a')
x('c')
x('b')

x('c')
x('c')

0 comments on commit 904111d

Please sign in to comment.