Chapter 7Using Test Doubles as Mocks and Stubs

We have a problem. We want to add credit-card processing to our project application so that we can make money. Testing the credit-card functionality presents immediate difficulties. For one thing, we don’t want to accidentally make a credit-card purchase during testing—that would be bad. But even if the purchase gateway provides a test sandbox, we still don’t want to depend on it for our unit tests to run. That network call is slow and we don’t want our passing tests to depend on the status of a remote server.

We have a different problem. We’d like to build our code in a very modular kind of way. In doing so, we’d like our tests to be as isolated as possible from dependencies on other parts of the ...

Get Rails 4 Test Prescriptions now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.