dimitarvp

dimitarvp

First time I hear about patch, looks very good actually, thanks!

1
Post #11
kanishka

kanishka OP

(also, I recommend matching on req body and params, because it is easy to overlook needing to re-record cassettes if you don’t use precise matching)

test config:

config :exvcr,
  vcr_cassette_library_dir: "test/fixture/vcr_cassettes",
  custom_cassette_library_dir: "test/fixture/custom_cassettes",
  filter_sensitive_data: [
    [pattern: "<PASSWORD>.+</PASSWORD>", placeholder: "PASSWORD_PLACEHOLDER"]
  ],
  filter_request_headers: ["Authorization"]

mix.exs

      {:exvcr, "~> 0.13.3", [only: :test]}

test

  use ExVCR.Mock, adapter: ExVCR.Adapter.Hackney
 ...

  setup_all do
    HTTPoison.start()
    :ok
  end

    test "..." do
      use_cassette "..." do
           # do the api calls
      end
  ...
0
Post #12
trisolaran

trisolaran

After reading this thread, I finally decided to give ex_vcr a try. So far I was using Bypass to test interactions with external APIs.

I’m using Tesla with Finch as my HTTP client.

So I have old test modules using Bypass and I’m writing a new test module that uses ex_vcr. What I noticed is that, if I run the new test in async mode (which ideally I would like to do), the test interferes with the other async tests that use Bypass. Basically, some tests fail because they don’t get the expected response.

I haven’t dug too much into it yet, but my initial assumption is that this is due to ex_vcr setting up global mocks for Finch. Could this be the issue?

Just checking if any of you has ever encountered this problem before or can give me a hint. Thanks!

2
Post #13
kanishka

kanishka OP

Looks like exvcr uses meck and meck notes the modules have to replaced globally - GitHub - eproxus/meck: A mocking library for Erlang · GitHub - so I don’t think you can use bypass and exvcr in the same test suite while using async.

1
Post #14
trisolaran

trisolaran

Thanks. Yes that’s what I figured too. meck - unlike Mox - apparently doesn’t support mocks local to a single process.

My workaround is to run the exvcr test synchronously - I have only one for now. As soon as I have more than one exvcr test, I will run them asynchronously in their own separate mix test execution. Best I can do for now I guess.

1
Post #15
LostKobrakai

LostKobrakai

Not just apparently. meck replaces the modules bytecode and reloads the module, which can only be done globally to the whole VM.

2
Post #16
— All posts loaded —