Fast forward 4 years and now there's a gem for that.
webmock . gem basically disables all outgoing api calls and then populates a bunch of code in the error response to insert. From there, you will adjust it to whatever code you want for this answer.
a source
to share