Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support exceptions without a #response method #10

Merged

Conversation

etagwerker
Copy link
Member

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 #<WebMock::NetConnectNotAllowedError:0x0000010cb73b28>
     # ./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 <top (required)>'

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!

…s not have that method, continue to raise the Exception.
rafaelivan added a commit that referenced this pull request Jun 11, 2014
Support exceptions without a #response method
@rafaelivan rafaelivan merged commit c758080 into ombulabs:master Jun 11, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants