Last active
February 12, 2021 14:49
-
-
Save hrom512/675c470428c7312d22f28829e94a700d to your computer and use it in GitHub Desktop.
VCR tips
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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