parroty / exvcr

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

How to use ExVCR with Finch? #166

Closed danicuki closed 7 months ago

danicuki commented 3 years ago

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 this example?

reisub commented 2 years ago

I believe this issue can now be closed since Finch support is there and documented in the README.

Stratus3D commented 8 months ago

I'm using this with Finch as documented and haven't had any issues. This can be closed.

parroty commented 7 months ago

Thanks for the follow-up 🙇