jjh42 / mock

Mocking library for Elixir language

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

trouble replicating examples

approaching236 opened this issue · comments

Forgive me if I'm accidentally asking a basic Elixir question, but I'm having trouble duplicating the results of the examples.

My test:

defmodule FanPublicApiTest do
  use ExUnit.Case, async: false

  import Mock

  describe "/v2.4/me" do
    test_with_mock 'response is parsable json', HTTPotion,
      [get: fn(_url) -> '{"broken json"' end] do
      response = HTTPotion.get("https://wwwstg.bandsintown.com/v2.4/me", [headers: ["Authorization": Application.fetch_env!(:gateway_regression, :authorization)]])
      IO.puts response.body
    end
  end
end

My results when running tests:

  1) test /v2.4/me response is parsable json (FanPublicApiTest)
     test/integration/fan_public_api_test.exs:7
     ** (UndefinedFunctionError) function HTTPotion.get/2 is undefined (module HTTPotion is not available)
     stacktrace:
       (httpotion) HTTPotion.get("https://wwwstg.bandsintown.com/v2.4/me", [headers: [Authorization: "Token token=**truncated**, auth_method=facebook, auth_login=100000917188511"]])
       test/integration/fan_public_api_test.exs:9: (test)

I've used the HTTPotion.get function successfully without the mocking, am I maybe missing something for my test helper?

@approaching236 you are mocking HTTPotion.get/1, but in test you are calling HTTPotion.get/2

Yes, that was exactly it.

I'm pretty familiar with Webmock, as I'm sure you are. In this type of case it would actually error in saying that a request was made that is not mocked (which is happening), but also list the registered mocks. That's definitely helped me bumble my way through my failing tests in the past.

Thanks so much for getting back to me. I really appreciate it.