Skip to content

Commit

Permalink
Better document the ignore_urls setting (#187)
Browse files Browse the repository at this point in the history
* Allow append to be passed to a previously nil setting

* Update README with ignore_urls instructions
  • Loading branch information
caioeps authored Sep 10, 2022
1 parent 69aaa49 commit 77348e2
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
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

0 comments on commit 77348e2

Please sign in to comment.