Skip to content

Instantly share code, notes, and snippets.

@tcrayford
Created April 10, 2012 19:22
Show Gist options
  • Save tcrayford/2353798 to your computer and use it in GitHub Desktop.
Save tcrayford/2353798 to your computer and use it in GitHub Desktop.
Note, the "don't stub external APIs" is a rule, but like all design/testing rules it *should* be broken with good judgement. Furthermore, like all design/testing rules, the best way to learn when to break it is to follow it rigorously until it leads you to a bad place.
Problems
--------
- Stubbing external APIs gives you no design feedback: you cannot change the third party API (unless you monkey patch, but seriously, Fuck That Shit. Since stubbing/mocking are primarily a design tool (for me), having to stub/mock something I cannot/will not change seems pointless.
- Stubbing a third party API relies on you having intimate understanding of the docs, including error conditions, timeouts etc. I'm not confident in my ability to successfully stub a third party API on each conditions.
The Solution
------------
- Wrap every third party API you use in a wrapper that lets your domain code express itself cleanly.
- Write integrated tests around your third party wrappers. The wrappers should be extremely thin.
- VCR is *really* quite good, and lets you have fast (enough) tests that use external HTTP apis, *without* you doing any stubbing/mocking.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment