Skip to content

Commit 6663b63

Browse files
committed
docs: fix typos and relative links, move code examples around
1 parent e1d32de commit 6663b63

File tree

2 files changed

+20
-20
lines changed

2 files changed

+20
-20
lines changed

README.md

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ Why is this important? The `Decoy` container tracks every fake that is created d
5959

6060
### Stubbing
6161

62-
A stub is a an object used in a test that is pre-configured to act in a certain way if called according to a spec, defined by a rehearsal. A "rehearsal" is simply a call to the stub inside of a `decoy.when` wrapper.
62+
A stub is a an object used in a test that is pre-configured to return a result or raise an error if called according to a specification. In Decoy, you specify a stub's call expectations with a "rehearsal", which is simply a call to the stub inside of a `decoy.when` wrapper.
6363

6464
By pre-configuring the stub with specific rehearsals, you get the following benefits:
6565

@@ -93,19 +93,9 @@ def test_get_item(decoy: Decoy):
9393
assert other_result is None
9494
```
9595

96-
### Verification
96+
### Verifying interactions
9797

98-
If you're coming from `unittest.mock`, you're probably more used to calling your code under test and _then_ verifying that your test double was called correctly. Asserting on mock call signatures after the fact can be useful, but **should only be used if the dependency is being called solely for its side-effect(s)**.
99-
100-
Verification of decoy calls after they have occurred be considered a last resort, because:
101-
102-
- If you're calling a method/function to get its data, then you can more precisely describe that relationship using [stubbing](#stubbing)
103-
- Side-effects are harder to understand and maintain than pure functions, so in general you should try to side-effect sparingly
104-
105-
Stubbing and verification of a decoy are **mutually exclusive** within a test. If you find yourself wanting to both stub and verify the same decoy, then one or more of these is true:
106-
107-
- The assertions are redundant
108-
- The dependency is doing too much based on its input (e.g. side-effecting _and_ calculating complex data) and should be refactored
98+
If you're coming from `unittest.mock`, you're probably used to calling your code under test and _then_ verifying that your dependency was called correctly. Decoy provides similar call verification using the same "rehearsal" mechanism that the stubbing API uses.
10999

110100
```python
111101
import pytest
@@ -123,15 +113,25 @@ def test_log_warning(decoy: Decoy):
123113
# call code under test
124114
some_result = log_warning("oh no!", logger)
125115

126-
# verify double called correctly
116+
# verify double called correctly with a rehearsal
127117
decoy.verify(logger.warn("oh no!"))
128118
```
129119

120+
Asserting that calls happened after the fact can be useful, but **should only be used if the dependency is being called solely for its side-effect(s)**. Verification of interactions in this manner should be considered a last resort, because:
121+
122+
- If you're calling a dependency to get data, then you can more precisely describe that relationship using [stubbing](#stubbing)
123+
- Side-effects are harder to understand and maintain than pure functions, so in general you should try to side-effect sparingly
124+
125+
Stubbing and verification of a decoy are **mutually exclusive** within a test. If you find yourself wanting to both stub and verify the same decoy, then one or more of these is true:
126+
127+
- The assertions are redundant
128+
- The dependency is doing too much based on its input (e.g. side-effecting _and_ calculating complex data) and should be refactored
129+
130130
### Matchers
131131

132-
Sometimes, when you're stubbing or verifying decoy calls (or really when you're doing any sort of equality assertion in a test), you need to loosen a given assertion. For example, you may want to assert that a double is called with a string, but you don't care what the full contents of that string is.
132+
Sometimes, when you're stubbing or verifying calls (or really when you're doing any sort of equality assertion in a test), you need to loosen a given assertion. For example, you may want to assert that a dependency is called with a string, but you don't care about the full contents of that string.
133133

134-
Decoy includes a set of matchers, which are simply Python classes with `__eq__` methods defined, that you can use in decoy rehearsals and/or assertions.
134+
Decoy includes a set of matchers, which are simply Python classes with `__eq__` methods defined, that you can use in rehearsals and/or assertions.
135135

136136
```python
137137
import pytest
@@ -148,12 +148,12 @@ def test_log_warning(decoy: Decoy):
148148

149149
# call code under test
150150
some_result = log_warning(
151-
"Oh no, something horrible went wrong with request ID abc123efg456",
151+
"Oh no, something went wrong with request ID abc123efg456",
152152
logger=logger
153153
)
154154

155155
# verify double called correctly
156156
decoy.verify(
157-
mock_logger.warn(matchers.StringMatching("something went wrong"))
157+
logger.warn(matchers.StringMatching("request ID abc123efg456"))
158158
)
159159
```

decoy/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ def test_create_something(decoy: Decoy):
8787
def when(self, _rehearsal_result: ReturnT) -> Stub[ReturnT]:
8888
"""Create a [Stub][decoy.stub.Stub] configuration using a rehearsal call.
8989
90-
See [stubbing](/#stubbing) for more details.
90+
See [stubbing](index.md#stubbing) for more details.
9191
9292
Arguments:
9393
_rehearsal_result: The return value of a rehearsal, used for typechecking.
@@ -117,7 +117,7 @@ def when(self, _rehearsal_result: ReturnT) -> Stub[ReturnT]:
117117
def verify(self, _rehearsal_result: Optional[ReturnT] = None) -> None:
118118
"""Verify a decoy was called using a rehearsal.
119119
120-
See [verification](/#verification) for more details.
120+
See [verification](index.md#verification) for more details.
121121
122122
Arguments:
123123
_rehearsal_result: The return value of a rehearsal, unused.

0 commit comments

Comments
 (0)