Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better document the ignore_urls setting #187

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion lib/exvcr/setting.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 16 additions & 0 deletions test/setting_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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