View Source ExVCR.Config (exvcr v0.15.2)
Assign configuration parameters.
Link to this section Summary
Functions
Initializes library dir to store cassette json files.
This function can be used to filter headers from saved requests.
This function can be used to filter options.
Replace the specified pattern with placeholder. It can be used to remove sensitive data from the cassette file.
Set the flag whether to filter-out url params when recording to cassettes. (ex. if flag is true, "param=val" is removed from "http://example.com?param=val").
Skip recording cassettes for localhost requests when set
Skip recording cassettes for urls requests when set
Sets a list of headers to remove from the response
Throw error if there is no matching cassette for an HTTP request
Link to this section Functions
Initializes library dir to store cassette json files.
- vcr_dir: directory for storing recorded json file.
- custom_dir: directory for placing custom json file.
This function can be used to filter headers from saved requests.
Examples
test "replace sensitive data in request header" do
ExVCR.Config.filter_request_headers("X-My-Secret-Token")
use_cassette "sensitive_data_in_request_header" do
body = HTTPoison.get!("http://localhost:34000/server?", ["X-My-Secret-Token": "my-secret-token"]).body
assert body == "test_response"
end
# The recorded cassette should contain replaced data.
cassette = File.read!("sensitive_data_in_request_header.json")
assert cassette =~ ""X-My-Secret-Token": "***""
refute cassette =~ ""X-My-Secret-Token": "my-secret-token""
# Now reset the filter
ExVCR.Config.filter_request_headers(nil)
end
This function can be used to filter options.
Examples
test "replace sensitive data in request options" do
ExVCR.Config.filter_request_options("basic_auth")
use_cassette "sensitive_data_in_request_options" do
body = HTTPoison.get!(@url, [], [hackney: [basic_auth: {"username", "password"}]]).body
assert body == "test_response"
end
# The recorded cassette should contain replaced data.
cassette = File.read!("sensitive_data_in_request_options.json")
assert cassette =~ ""basic_auth": "***""
refute cassette =~ ""basic_auth": {"username", "password"}"
# Now reset the filter
ExVCR.Config.filter_request_options(nil)
end
Replace the specified pattern with placeholder. It can be used to remove sensitive data from the cassette file.
Examples
test "replace sensitive data" do
ExVCR.Config.filter_sensitive_data("<PASSWORD>.+</PASSWORD>", "PLACEHOLDER")
use_cassette "sensitive_data" do
assert HTTPotion.get("http://something.example.com", []).body =~ ~r/PLACEHOLDER/
end
# Now clear the previous filter
ExVCR.Config.filter_sensitive_data(nil)
end
Set the flag whether to filter-out url params when recording to cassettes. (ex. if flag is true, "param=val" is removed from "http://example.com?param=val").
Skip recording cassettes for localhost requests when set
Skip recording cassettes for urls requests when set
Sets a list of headers to remove from the response
Throw error if there is no matching cassette for an HTTP request