kauplus/mercadopago — pull request #10 by etagwerker (2014-06-05 14:22:29+00:00)
Title: Support exceptions without a #response method

Hi!

While trying to use `webmock` with this gem, I ran into this issue today:

```
1) PaymentGateway PaymentGateway::MercadoPagoGateway#state asynchronous credential check which actually runs should mark the state as confirmed
Failure/Error: CheckMercadoPagoCredentialsJob.new.perform(@mercado_pago.id)
NoMethodError:
undefined method `response' for #
# ./app/models/payment_gateway/mercado_pago_gateway.rb:130:in `check_credentials'
# ./app/jobs/check_mercado_pago_credentials_job.rb:21:in `perform'
# ./spec/models/payment_gateway/payment_gateway_spec.rb:32:in `block (4 levels) in '
```

I expected to see something like this:

```
1) PaymentGateway PaymentGateway::MercadoPagoGateway#state asynchronous credential check which actually runs should mark the state as confirmed
Failure/Error: CheckMercadoPagoCredentialsJob.new.perform(@mercado_pago.id)
WebMock::NetConnectNotAllowedError:
Real HTTP connections are disabled. Unregistered request: POST https://api.mercadolibre.com/oauth/token with body 'client_id=1234&client_secret=SECRET&grant_type=client_credentials' with headers {'Accept'=>'application/json', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Content-Type'=>'application/x-www-form-urlencoded', 'User-Agent'=>'Ruby'}

You can stub this request with the following snippet:

stub_request(:post, "https://api.mercadolibre.com/oauth/token").
with(:body => {"client_id"=>"1234", "client_secret"=>"SECRET", "grant_type"=>"client_credentials"},
:headers => {'Accept'=>'application/json', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Content-Type'=>'application/x-www-form-urlencoded', 'User-Agent'=>'Ruby'}).
to_return(:status => 200, :body => "", :headers => {})

============================================================
```

This pull request fixes this issue. If an Exception doesn't have the `#response` method,
it will work.

Check it out.

Thanks!