Our application design allows us multiple ways to simulate errors for testing purposes:
We can make an API call to the actual service that results in an error and capture the result using VCR. We can use this approach in an integration or adapter test.
We can stub a method that’s internal to the adapter. For example, we can stub the client method to return a double that simulates an API error. We’d use this in an adapter test.
We can stub the adapter to return an unexpected value in a client test.
Which approach you choose depends on the details of the library you’re working with. Often, stubbing the external service makes sense for the same reason that stubbing ActiveRecord methods does—crafting a call that will reliably ...