You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+18-18Lines changed: 18 additions & 18 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -59,7 +59,7 @@ Why is this important? The `Decoy` container tracks every fake that is created d
59
59
60
60
### Stubbing
61
61
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.
63
63
64
64
By pre-configuring the stub with specific rehearsals, you get the following benefits:
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.
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
+
130
130
### Matchers
131
131
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.
133
133
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.
0 commit comments