My project uses Finch to make parallel HTTP requests.
I tried to add VCR to my tests, but the HTTP requests are still happening.
Here is my test:
defmodule MyClientTest do
use ExUnit.Case, async: true
use ExVCR.Mock #, adapter: ExVCR.Adapter.Httpc
setup do
ExVCR.Config.cassette_library_dir("fixture/vcr_cassettes")
:ok
end
test "list_apps" do
use_cassette "list_apps" do
list_apps = MyClient.list_apps
assert MyClient.list_apps == ["app1", "app2"]
end
end
end
I see a list_apps.json
file in the fixture/vcr_cassettes
, but its content is only []
Here is my MyClient module:
defmodule MyClient do
alias Finch.Response
def child_spec do
{Finch,
name: __MODULE__,
pools: %{
"https://myapp.com" => [size: 100]
}}
end
def applications_response do
:get
|> Finch.build("https://myapp.com/v2/apps.json")
|> Finch.request(__MODULE__)
end
def handle_applications_response({:ok, %Response{body: body}}) do
body
|> Jason.decode!()
end
end
def list_apps do
handle_applications_response(applications_response())
end
end
How to apply VCR to my HTTP Finch calls?