parroty / exvcr

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

ibrowse example is not working #77

Open JonRCahill opened 8 years ago

JonRCahill commented 8 years ago

Hi I have tried to setup exvcr and use the example to ensure everything is working but I keep getting the following error:

** (ErlangError) erlang error: {:not_mocked, :ibrowse}
     stacktrace:
       src/meck_proc.erl:118: :meck_proc.set_expect/2
       src/meck.erl:234: :meck.expect/3
       (elixir) lib/enum.ex:651: Enum."-each/2-lists^foreach/1-0-"/2
       (elixir) lib/enum.ex:651: Enum.each/2
       test/lib/mail_chimp_test.exs:46: (test)

my code is as follows (the example provided by exvcr):

defmodule ExtraTurn.MailChimpTest do
  use ExUnit.Case, async: false
  use ExVCR.Mock

  setup_all do
    ExVCR.Config.cassette_library_dir("fixture/vcr_cassettes")
    :ok
  end

  test "example single request" do
    use_cassette "example_ibrowse" do
      :ibrowse.start
      {:ok, status_code, _headers, body} = :ibrowse.send_req('http://example.com', [], :get)
      assert status_code == '200'
      assert to_string(body) =~ ~r/Example Domain/
    end
  end

  test "httpotion" do
    use_cassette "example_httpotion" do
      HTTPotion.start
      assert HTTPotion.get("http://example.com", []).body =~ ~r/Example Domain/
    end
  end
end

I am using the latest elixir version, 1.3.4:

Erlang/OTP 19 [erts-8.1] [source] [64-bit] [smp:8:8] [async-threads:10] [hipe] [kernel-poll:false] [dtrace]

Elixir 1.3.4

and using Phoenix 1.2.1 (but I don't think that will affect anything).

I have tried using both the latest version on hex.pm and the latest github version.

Any help would be great!

parroty commented 7 years ago

Sorry being late to respond. Is it possible to post your mix.exs? (how deps defined?) The above mentioned code seems working in my environment with following deps definition and would like to isolate the condition.

defmodule SomeModule.Mixfile do
  use Mix.Project

...

  defp deps do
    [
      {:exvcr, "~> 0.8", only: :test},
      {:ibrowse, "~> 4.2"},
      {:httpotion, "~> 3.0"}
    ]
  end
end
epergo commented 7 years ago

Hi!! I had the same problem and was because I didn't know ibrowse is a mandatory dependency to have installed.

Thx @parroty !

yordis commented 5 years ago

Same issue here, I had httpoison but I didn't have ibrowse as a deps. This is a little bit odd since httpoison uses ibrowse.

DaniruKun commented 2 years ago

Hmm I didn't have any problem using HTTPotion, just make sure that you have this block in your test module:

setup_all do
    HTTPoison.start()
    :ok
  end