geocoder icon indicating copy to clipboard operation
geocoder copied to clipboard

Testing API Interactions

Open alexreisner opened this issue 8 years ago • 1 comments

Currently the test suite stubs HTTP requests in a somewhat unsophisticated way, implementing proprietary logic about raising errors and returning data. This works pretty well (and is relatively easy to understand) but has a few shortcomings:

  • doesn't test specific aspects of the HTTP/HTTPS connection (see, eg, #1035)
  • doesn't test authentication (either HTTP Basic or with API keys)
  • doesn't test code inside of make_api_request (because it's stubbed)
  • defines response content and headers in different places (content is in a file, status code and headers are defined in a method)

I'm open to discussion about how to improve the above. However, note that any solution must:

  • be able to simulate requests to APIs that require authentication, without storing credentials in the Git repo (ie: everyone needs to be able to run these tests)

alexreisner avatar May 09 '16 19:05 alexreisner

WebMock looks like good fit as it can handle:

  • authentication
  • most connection-specific things (timeouts, etc)
  • it mocks on level of HTTP-adapters, so no need to stub any gem methods
  • responses can be stored in file with status code and headers (see curl -is in its readme)

Envek avatar May 12 '16 13:05 Envek