parroty / exvcr

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

Doesn't mock requests...... #32

Open OpakAlex opened 8 years ago

OpakAlex commented 8 years ago
defmodule AbrPayments.Api.V1.PaymentsControllerTest do
  use AbrPayments.ConnCase
  use ExUnit.Case, async: false
  use ExVCR.Mock, adapter: ExVCR.Adapter.Httpc

  setup_all do
    AbrPayments.Abr.Http.start
    ExVCR.Config.cassette_library_dir("fixture/vcr_cassettes", "fixture/custom_cassettes")
    :ok
  end

  test "returns 401 if don't send token" do
    conn = conn
            |> get(payments_path(conn, :create))
            |> doc
    assert conn.status == 401
  end

  test "return 422 if accounts in form not user account" do
    use_cassette :stub, [url: "http://localhost:3000/api/v1/accounts/for_payments", body: "Stub Response"] do
      {:ok, body} = HTTPoison.get!("http://localhost:3000/api/v1/accounts/for_payments", [])
      IO.inspect(body)
    end
  end
test "stub request works for HTTPoison" do
  use_cassette :stub, [url: "http://www.example.com", body: "Stub Response"] do
    response = HTTPoison.get!("http://www.example.com")
    assert response.body =~ ~r/Stub Response/
    assert response.headers["Content-Type"] == "text/html"
    assert response.status_code == 200
  end
end
end
OpakAlex commented 8 years ago

It always do request to real sites....shit

parroty commented 8 years ago

Is it possible to retry by updating the code as following?

from

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

to

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

HTTPoison is using hackney instead of httpc, and the misbehavior might be caused by the mismatch. https://github.com/parroty/exvcr/#example-with-hackney

StanBright commented 7 years ago

I can confirm that HTTPoison works with adapter: ExVCR.Adapter.Hackney