smartystreets / smartystreets-ruby-sdk

The official client libraries for accessing SmartyStreets APIs from Ruby
https://smartystreets.com/docs/sdk/ruby
Apache License 2.0
23 stars 25 forks source link

Doesn't Play Well with VCR #10

Closed andremleblanc closed 6 years ago

andremleblanc commented 6 years ago

Was getting the below error message when running tests.

NoMethodError:
       undefined method `<' for nil:NilClass
     # ~.../smartystreets_ruby_sdk/retry_sender.rb:17:in `block in send'

Line that is breaking:

break if response.status_code < STATUS_INTERNAL_SERVER_ERROR

Looks like response is nil in this case.

MouaYing commented 6 years ago

@andremleblanc - Are you sure this is related to VCR? It could just be that your test doesn't provide a mock response.

andremleblanc commented 6 years ago

Not sure, I'll try to reproduce the issue over the weekend and submit a PR if appropriate.

I noticed this when replacing an older third-party gem with this one for communicating to SmartyStreets. The tests would previously raise an error about trying to make an unrecognized http call (if the calls changed from what was recorded in the cassette); my goal would be to make that the behavior again so the error message is more clear.

andremleblanc commented 6 years ago

Created PR #11 to illustrate the behavior and provide a solution for it. You can run the example with ruby test/vcr_test.rb to see the expected VCR error message.

/Users/andreleblanc/.rvm/gems/ruby-2.4.1/gems/vcr-3.0.3/lib/vcr/request_handler.rb:97:in `on_unhandled_request':  (VCR::Errors::UnhandledHTTPRequestError)

================================================================================
An HTTP request has been made that VCR does not know how to handle:
  POST https://us-street.api.smartystreets.com/street-address?auth-id&auth-token

There is currently no cassette in use. There are a few ways
you can configure VCR to handle this request:
...

Removing the .to_i casting in retry_sender.rb will show you the previous error message.

/Users/andreleblanc/Drive/.dev/smartystreets-ruby-sdk/lib/smartystreets_ruby_sdk/retry_sender.rb:17:in `block in send': undefined method `<' for nil:NilClass (NoMethodError)

You probably don't want the extra dev dependencies and failing test, let me know if the solution is okay and I'll clean up the PR.

MouaYing commented 6 years ago

@andremleblanc - The solution looks good. If you wouldn't mind cleaning up the PR, we'd be delighted to merge it in. Thanks!

andremleblanc commented 6 years ago

Awesome, cleaned it up. Should be good to go! 👍

MouaYing commented 6 years ago

Thanks! I've merged it in.