Ruby on Rails: Best way to test a failed call to a third party API

I would recommend using something like webmock to mock all of your http requests (not just to mock a failed request); it'll greatly speed up your test suite instead of having to actually hit the third party service every time you run the tests.

Webmock supports Rest Client and Test::Unit. Just put this code in your test/test_helper.rb file:

require 'webmock/test_unit' 

As an example, to test a network timeout:

stub_request(:any, 'www.example.net').to_timeout
RestClient.post('www.example.net', 'abc')    # ===> RestClient::RequestTimeout