Skip to content

Commit

Permalink
Resolve Duplicate Docs Warnings (#180)
Browse files Browse the repository at this point in the history
Warnings were being issued regarding duplicate documentation
declarations. Here's an example:

```
warning: redefining @doc attribute previously set at line 27.

Please remove the duplicate docs. If instead you want to override a previously defined @doc, attach the @doc attribute to a function head (the function signature not followed by any do-block). For example:

    @doc """
    new docs
    """
    def use_cassette(...)

  lib/exvcr/mock.ex:48: ExVCR.Mock.use_cassette/3
```

This change resolves these warnings by merging documentation and adding
examples that were already available in the README file.
  • Loading branch information
jherdman authored Sep 10, 2022
1 parent a9fcf03 commit 5201278
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 28 deletions.
66 changes: 52 additions & 14 deletions lib/exvcr/config.ex
Original file line number Diff line number Diff line change
Expand Up @@ -19,45 +19,83 @@ defmodule ExVCR.Config do
@doc """
Replace the specified pattern with placeholder.
It can be used to remove sensitive data from the casette 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
"""
def filter_sensitive_data(pattern, placeholder) do
Setting.append(:filter_sensitive_data, {pattern, placeholder})
end


@doc """
Clear the previously specified filter_sensitive_data lists.
"""
def filter_sensitive_data(nil) do
Setting.set(:filter_sensitive_data, [])
end

@doc """
Clear the previously specified filter_request_headers lists.
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
"""
def filter_request_headers(nil) do
Setting.set(:filter_request_headers, [])
end

@doc """
Replace the specified request header with placeholder.
It can be used to remove sensitive data from the casette file.
"""
def filter_request_headers(header) do
Setting.append(:filter_request_headers, header)
end

@doc """
Clear the previously specified filter_request_options lists.
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
"""
def filter_request_options(nil) do
Setting.set(:filter_request_options, [])
end

@doc """
Replace the specified request header with placeholder.
It can be used to remove sensitive data from the casette file.
"""
def filter_request_options(header) do
Setting.append(:filter_request_options, header)
end
Expand Down
22 changes: 8 additions & 14 deletions lib/exvcr/mock.ex
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,14 @@ defmodule ExVCR.Mock do
end

@doc """
Provides macro to mock response based on specified parameters.
Provides macro to trigger recording/replaying http interactions.
## Options
- `:match_requests_on` A list of request properties to match on when
finding a matching response. Valid values include `:query`, `:headers`,
and `:request_body`
"""
defmacro use_cassette(:stub, options, test) do
quote do
Expand All @@ -45,16 +52,6 @@ defmodule ExVCR.Mock do
end
end

@doc """
Provides macro to trigger recording/replaying http interactions.
## Options
- `:match_requests_on` A list of request properties to match on when
finding a matching response. Valid values include `:query`, `:headers`,
and `:request_body`
"""
defmacro use_cassette(fixture, options, test) do
quote do
recorder = Recorder.start(
Expand All @@ -77,9 +74,6 @@ defmodule ExVCR.Mock do
end
end

@doc """
Provides macro to trigger recording/replaying http interactions with default options.
"""
defmacro use_cassette(fixture, test) do
quote do
use_cassette(unquote(fixture), [], unquote(test))
Expand Down

0 comments on commit 5201278

Please sign in to comment.