diff --git a/README.md b/README.md index 3868841..f2cfc5f 100644 --- a/README.md +++ b/README.md @@ -270,6 +270,22 @@ test "replace sensitive data in request options" do end ``` +#### Allowed hosts + +The `:ignore_urls` can be used to allow requests to be made to certain hosts. + +```elixir +setup do + ExVCR.Setting.set(:ignore_urls, [~/example.com/]) + ExVCR.Setting.append(:ignore_urls, ~/anotherurl.com/) +end + +test "an actual request is made to example.com" do + HTTPoison.get!("https://example.com/path?query=true") + HTTPoison.get!("https://anotherurl.com/path?query=true") +end +``` + #### Ignoring query params in URL If `ExVCR.Config.filter_url_params(true)` is specified, query params in URL diff --git a/lib/exvcr/setting.ex b/lib/exvcr/setting.ex index b70769c..fb3970b 100644 --- a/lib/exvcr/setting.ex +++ b/lib/exvcr/setting.ex @@ -14,7 +14,10 @@ defmodule ExVCR.Setting do end def append(key, value) do - set(key, [value | ExVCR.Setting.get(key)]) + case __MODULE__.get(key) do + [_ | _] = values -> __MODULE__.set(key, [value | values]) + _ -> __MODULE__.set(key, [value]) + end end defp setup do diff --git a/test/setting_test.exs b/test/setting_test.exs index 4e6bc72..15f2081 100644 --- a/test/setting_test.exs +++ b/test/setting_test.exs @@ -27,4 +27,20 @@ defmodule ExVCR.SettingTest do ExVCR.Setting.set(:response_headers_blacklist, ["Content-Type", "Accept"]) assert ExVCR.Setting.get(:response_headers_blacklist) == ["Content-Type", "Accept"] end + + test "set ignore_urls" do + ExVCR.Setting.set(:ignore_urls, ["example.com"]) + assert ExVCR.Setting.get(:ignore_urls) == ["example.com"] + end + + test "append ignore_urls when there are no existing values" do + ExVCR.Setting.append(:ignore_urls, "example.com") + assert ExVCR.Setting.get(:ignore_urls) == ["example.com"] + end + + test "append ignore_urls when there are existing values" do + ExVCR.Setting.set(:ignore_urls, [~r/example.com/]) + ExVCR.Setting.append(:ignore_urls, ~r/example2.com/) + assert ExVCR.Setting.get(:ignore_urls) == [~r/example2.com/, ~r/example.com/] + end end