O'Reilly logo

Rails 4 Test Prescriptions by Noel Rappin

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

Testing for Error Cases

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 ...

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