Your Turn
Whew! We gave you a lot to chew on in this chapter, from broad advice on test doubles to fine-grained design nuances. Here are just some of the principles we explored over several code examples:
- Construct your test environment carefully.
- Watch out for the “stubject.”
- Know the risks of partial doubles.
- Favor explicit dependency injection over more implicit techniques.
- Avoid faking an interface you don’t control.
- Look for high-fidelity fakes.
- Wrap third-party interfaces.
That’s a lot to keep in your head, but we’re definitely not asking you to do that! All of these bits of advice stem from one key practice: constructing your test environment carefully. Remember the laboratory metaphor when you’re writing your specs, and you should be fine.
Get Effective Testing with RSpec 3 now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.