parroty / exvcr

HTTP request/response recording library for elixir, inspired by VCR.
MIT License
727 stars 132 forks source link

Ignoring not matching urls for cassettes #96

Open wli0503 opened 7 years ago

wli0503 commented 7 years ago

When using HTTPoison with :hackney, I got the error of response for [URL:#{params[:url]}, METHOD:#{params[:method]}] was not found. The requests are not the same one as recorded in the cassettes so I guess that's the reason it's not working as expected.

So I propose when using ExVCR mockups, we have a switch as bypass. Just like custom, when set to true, it will ignore all the requests that are not specified in the recorded cassettes. Here's an example:

  use ExVCR.Mock, adapter: ExVCR.Adapter.Hackney
  ...hooks and other test cases...
  test "it will bypass if the cassette did not match the request" do
    use_cassette "no_match", custom: true, bypass: true do
         HTTPoison.start
         assert HTTPoison.get("http://not_match_cassette.com").status_code == 200
     end
  end

By combining the custom switch and the bypass switch, we now have the request to be passed directly to the server instead of using a pre-recorded one.

See PR #97 for details. Let me know if you have any question or concern regarding to it. Any discussion is welcome.

parroty commented 7 years ago

Thanks for the feedback and suggestions. Is it possible to show the actual response from server (or recorded cassette file)? I'm wondering which part is actually causing the not-found error. It might be one way to add bypass type of option, but not sure enough yet. I think there're some other options to ignore certain part of attributes in the request.

sadir commented 6 years ago

Hi @parroty - I've discovered a need for this functionality today. Is this planned/not going to happen/needs help and is open for PRs?