Testing Web APIs with RSpec and VCR

I am writing an API wrapper as a gem and I want to test API responses using RSpec.

The problem is that all API requests are executed using GET and contain the API key in the URL:

eg. game/metadata/{api_key}

This poses problems for testing since I don't want to store the API key in the git repository history. Is there a way I can fulfill these specifications, preferably with RSpec / VCR, and not store the API key in version control?

I tried using environment variables, but the VCR saves the entire request, not just the response body.

+7
source share
1 answer

The VCR has a configuration option specifically for such cases:

 VCR.configure do |c| c.filter_sensitive_data("<API_KEY>") { MyAPIClient.api_key } end 

See https://www.relishapp.com/myronmarston/vcr/docs/configuration/filter-sensitive-data for more details.

+20
source

All Articles