O'Reilly logo

Effective Testing with RSpec 3 by Myron Marston, Ian Dees

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Wrapping a Third-Party Dependency

While high-fidelity fakes can save a lot of trouble, they can still leave your logic coupled to a third-party API. This coupling has a few downsides:

  • Your code will be exposed to the complexities of a (potentially) large API.
  • Changes to the dependency’s interface will ripple throughout your system.
  • Testing is difficult, since you can’t easily and safely replace the third-party code with a double.

To avoid these pitfalls, you can wrap the dependency—that is, write your own layer that delegates to it internally. Using a wrapper (also known as a gateway or adapter when you’re wrapping an API) gives you a couple of key advantages:

  • You can create a small, simple interface tailored exactly to your needs.
  • You can safely ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required