Skip to content

Commit a5c02e4

Browse files
ʇɹǝqƃǝᴉs puɐloɹquii
ʇɹǝqƃǝᴉs puɐloɹ
authored andcommitted
Update mocking.md (quii#215)
* 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
1 parent 4578197 commit a5c02e4

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

mocking.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,7 @@ We now have our function and its 2 important properties properly tested.
480480

481481
## Extending Sleeper to be configurable
482482

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.
484484

485485
### Write the test first
486486

@@ -493,7 +493,7 @@ type ConfigurableSleeper struct {
493493
}
494494
```
495495

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:
497497

498498
```go
499499
type SpyTime struct {
@@ -553,7 +553,7 @@ func (c *ConfigurableSleeper) Sleep() {
553553
}
554554
```
555555

556-
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.
557557

558558
### Cleanup and refactor
559559

@@ -568,7 +568,7 @@ func main() {
568568

569569
If we run the tests and the program manually, we can see that all the behavior remains the same.
570570

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.
572572

573573
## But isn't mocking evil?
574574

0 commit comments

Comments
 (0)