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
* Update mocking.md
Add a little bit of reasoning why it makes sense to have a configurable sleeper.
* Fix typo
* Fix wording about ConfigurableSleeper intention
* Reducing the Encap vs. Gener. discussion to a hint
Copy file name to clipboardExpand all lines: mocking.md
+4-4Lines changed: 4 additions & 4 deletions
Original file line number
Diff line number
Diff line change
@@ -480,7 +480,7 @@ We now have our function and its 2 important properties properly tested.
480
480
481
481
## Extending Sleeper to be configurable
482
482
483
-
A nice feature would be for the `Sleeper` to be configurable.
483
+
A nice feature would be for the `Sleeper` to be configurable. This means that we can adjust the sleep time in our main program.
484
484
485
485
### Write the test first
486
486
@@ -493,7 +493,7 @@ type ConfigurableSleeper struct {
493
493
}
494
494
```
495
495
496
-
We are using `duration` to configure the time slept and `sleep` as a way to pass in a sleep function. The signature of `sleep` is the same as for `time.Sleep` allowing us to use `time.Sleep` in our real implementation and a spy in our tests.
496
+
We are using `duration` to configure the time slept and `sleep` as a way to pass in a sleep function. The signature of `sleep` is the same as for `time.Sleep` allowing us to use `time.Sleep` in our real implementation and the following spy in our tests:
With this change all of the test should be passing again.
556
+
With this change all of the tests should be passing again and you might wonder why all the hassle as the main program didn't change at all. Hopefully it becomes clear after the following section.
557
557
558
558
### Cleanup and refactor
559
559
@@ -568,7 +568,7 @@ func main() {
568
568
569
569
If we run the tests and the program manually, we can see that all the behavior remains the same.
570
570
571
-
Since we are using the `ConfigurableSleeper`, it is safe to delete the `DefaultSleeper` implementation. Wrapping up our program.
571
+
Since we are using the `ConfigurableSleeper`, it is now safe to delete the `DefaultSleeper` implementation. Wrapping up our program and having a more [generic](https://stackoverflow.com/questions/19291776/whats-the-difference-between-abstraction-and-generalization) Sleeper with arbitrary long countdowns.
0 commit comments