Skip to content

Commit

Permalink
Add config to VCR lesson.
Browse files Browse the repository at this point in the history
  • Loading branch information
KatBrandt committed Aug 19, 2024
1 parent 5e453bb commit 990f882
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions module3/lessons/testing_tools_for_api_consumption.md
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,20 @@ end

This example uses a "default cassette options" flag, setting a re-record interval of 7 days for all cassettes. You can still override this on individual tests which use `VCR.use_cassette()`, so you could set a general flag of, say, `30.days` but a particular test could be set to `7.days` instead to expire earlier.

## What if I don't want to stub a request?

When VCR is installed, it will assume you want to block every network request in all of your tests. Sometimes though, we don't want VCR to interrupt the network call. We can add an additional line of configuration to prevent VCR from throwing an error when we're intentionally trying to make an API call.
```ruby
VCR.configure do |config|
config.cassette_library_dir = 'spec/fixtures/vcr_cassettes'
config.hook_into :webmock
config.filter_sensitive_data('DONT_SHARE_MY_PROPUBLIC_SECRET_KEY') { Rails.application.credentials.propublica[:key] }
config.default_cassette_options = { re_record_interval: 7.days }
config.configure_rspec_metadata!
config.allow_http_connectins_when_no_cassette = true
end
```

## Checks for Understanding

- What are some reasons we don't want our tests to make real API calls?
Expand Down

0 comments on commit 990f882

Please sign in to comment.