

Ruby Testing and External Dependencies - dinomite
http://blog.palominolabs.com/2013/05/06/ruby-testing-and-external-dependencies/

======
timdorr
An interesting solution, but somewhat troublesome if you're running just one
unit test that doesn't touch that backend service.

If it's retrieving data over HTTP, you can just use the awesome VCR gem:
<https://github.com/vcr/vcr> It's awesome for testing HTTP APIs (along with
webmock), since it works relatively transparently and makes your tests far
less fragile.

~~~
dinomite
Mocks can be useful for testing interfaces (APIs with a strictly defined
behavior), but they have significant limitations. Mocks are stubs of a class
at the time the test was written—it's very easy for them to be forgotten and
no longer mirror the behavior of the mocked class. Additionally, they are code
that increases the complexity of the tests making it harder to comprehend what
the test is doing.

Starting up a separate system simply to run one unit test does seem like a
hassle, but in practice it hasn't slowed down our tests one bit. The external
dependency is started as a background process, spinning up at the same time
rspec is bootstrapping. We also have a number of different tests that interact
with the service, so the value is even greater.

These (<http://stackoverflow.com/q/38181/17339>) questions
(<http://stackoverflow.com/q/1595166/17339>) on Stack Overflow have some
instructive discussion on using mocks and stubs.

