Skip to content

Instantly share code, notes, and snippets.

@hrom512
Last active February 12, 2021 14:49
Show Gist options
  • Save hrom512/675c470428c7312d22f28829e94a700d to your computer and use it in GitHub Desktop.
Save hrom512/675c470428c7312d22f28829e94a700d to your computer and use it in GitHub Desktop.
VCR tips
VCR_COMMON_HEADERS = %w[Content-Type Accept Accept-Encoding Authorization].freeze
VCR.configure do |config|
common_headers_proc = ->(request) { request.headers.slice(*VCR_COMMON_HEADERS) }
config.register_request_matcher :common_headers do |request1, request2|
common_headers_proc[request1] == common_headers_proc[request2]
end
# https://github.com/vcr/vcr/blob/master/features/request_matching/README.md
config.default_cassette_options = {
match_requests_on: [:method, :uri, :body, :common_headers],
}
config.before_record do |item|
item.response.body.force_encoding('UTF-8')
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment