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

match_request_on :headers, but specifying what headers it should match #134

Open
IceDragon200 opened this issue Apr 13, 2018 · 2 comments
Open

Comments

@IceDragon200
Copy link

Is it possible to use match_request_on :headers, but then specify which headers it should match?

If not then I suggest something like:

use_cassette "my_cassette", match_requests_on: [headers: [only: ["content-type", "soapaction"]]] do
  # do stuff
end
@type t :: [
  {:match_requests_on, [
    :headers |
    {:headers [
      only: [String.t],
      except: [String.t]
    ]}
  ]}
]

The default :headers option would still be kept if no filtering is required.

The reasoning behind this request is to ignore some dynamic headers that would be difficult to remove/disable just for testing (e.g. a user-agent which uses the current application version), but always invalidates recorded cassettes because of their nature.

@bryanhuntesl
Copy link
Contributor

Is it possible to use match_request_on :headers, but then specify which headers it should match?

If not then I suggest something like:

use_cassette "my_cassette", match_requests_on: [headers: [only: ["content-type", "soapaction"]]] do
  # do stuff
end
@type t :: [
  {:match_requests_on, [
    :headers |
    {:headers [
      only: [String.t],
      except: [String.t]
    ]}
  ]}
]

The default :headers option would still be kept if no filtering is required.

The reasoning behind this request is to ignore some dynamic headers that would be difficult to remove/disable just for testing (e.g. a user-agent which uses the current application version), but always invalidates recorded cassettes because of their nature.

Good for testing ETag / "If-None-Match" interactions

@bryanhuntesl
Copy link
Contributor

I've hit this as well - I would have like to have verified this worked - it's pretty essential to the project (github event poller).

https://github.com/esl/ex_github_poller/blob/0774b23079baf66acecf4bab6d96595075d8a6ef/test/ex_github_poller_test.exs#L27-L38

  test "list events etag " do
    ExVCR.Config.filter_request_headers("Authorization")
    use_cassette "list_events_etag" , match_requests_on: [ :headers, :query , :request_body ] do

      x = ExGithubPoller.events("bryanhuntesl", "test_repo", %ExGithubPoller.Param{} )
      assert length(x.events) == 152

      y = ExGithubPoller.events("bryanhuntesl", "test_repo", %ExGithubPoller.Param{etag: x.etag} )
      assert length(y.events) == 0
      assert y.limit_remaining == x.limit_remaining

    end
  end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants