High-Fidelity Fakes

When you work with rspec-mocks, you’re using fake behavior supplied by RSpec. There are other kinds of test doubles, though. You can use an alternative implementation designed to drop into your tests in place of the real thing. Because these mimic the original library’s interface and behavior closely, we call them high-fidelity fakes.

For instance, the FakeFS gem makes it easy to test code that interacts with the filesystem.[109] FakeRedis acts just like the Redis data store but doesn’t require a network connection or a running server.[110] If you use Braintree for credit-card processing, Fake Braintree can stand in during testing.[111]

Sometimes, a library ships with its own high-fidelity fake. The Fog gem, which wraps ...

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.