Skip to content
This repository has been archived by the owner on Jul 21, 2024. It is now read-only.

Chapter 10: Fix VCR example #85

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Chapter 10: Fix VCR example #85

wants to merge 2 commits into from

Conversation

ruralocity
Copy link
Member

If you attempted to run the tests added in chapter 10 since July 1, 2018, you may have noticed that the example using VCR to record an interaction with an external HTTP service no longer works. The IP geocoding service in use before, freegeoip, has been discontinued, and the geocoder gem now defaults to IPInfo.io. Thanks to @JunichiIto for pointing this out to me in #84

This pull request contains code changes necessary to fix this issue, so you can continue to work through examples in the book. I've provided the steps in two standalone commits:

  1. Update the geocoder gem to the latest version, so it uses IPInfo.io by default, and you don't need to do any extra configuration in the sample app. This applies to chapter 2 in the book, where we first look at the untested application.
  2. Re-record the the VCR cassette for the sample code, then adjust the geocoding-related spec to reflect a difference in the new IP geocoding service's output. Again, this applies to chapter 10.

Please click through the commits for additional commentary and to see what's changed from the current book version to now.

The Freegeoip service that's the default in our current version of the
geocoder gem has been discontinued. Geocoder now uses IPInfo.io as its
default.

Update the geocoder version to 1.4.9 to use the new default.

#84
Geocoder now uses the IPInfo.io service as its default for IP-based
geocoding, since the previous default service is no longer available.
This breaks test examples in chapter 10 of Everyday Rails Testing with
RSpec, which uses a geocoding example to record a VCR cassette of
network activity.

Re-record the cassette to use IPInfo.io. It looks like this service's
response is slightly different than the previous service, so update the
expected response to reflect that.

IPInfo.io doesn't require an API key for less than 1,000 requests a day,
and is limited to non-HTTPS requests only. These limitations should be
adequate for the sake of demonstration in the book, but should not be
used as-is in a production environment. See IPInfo.io's pricing page to
acquire an API key for the service.

In addition, you'll want to ensure that secrets like API keys are
filtered from cassettes when using VCR to record any service requiring
an API key, username/password, or other secret. See
https://relishapp.com/vcr/vcr/v/3-0-3/docs/configuration/filter-sensitive-data
for details on filtering sensitive data in the version of VCR used in
the current version of  Everyday Rails Testing with RSpec.

#84
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant