-
Notifications
You must be signed in to change notification settings - Fork 357
Closed
Description
Since version 1.14.0, Tesla.Mock.mock has stopped working for processes spawned by a test or a callback. I think this is a regression due to #750.
Reproduce
Version 1.13
# tesla_1.13_mock.exs
Mix.install([
{:jason, "~> 1.4"},
{:tesla, "~> 1.13.0"}
])
Application.ensure_all_started(:tesla)
Application.put_env(:tesla, :adapter, Tesla.Mock)
defmodule MyAgent do
use Agent
def start_link(_arg) do
Agent.start_link(fn -> Tesla.get!("https://httpbin.org/get") end, name: __MODULE__)
end
end
Tesla.Mock.mock(fn _ -> Tesla.Mock.json(%{"url" => "https://httpbin.org/get"}) end)
{:ok, _pid} = MyAgent.start_link([])
IO.inspect(:sys.get_state(MyAgent), label: "state")$ elixir tesla_1.13_mock.exs
state: %Tesla.Env{
method: nil,
url: "",
query: [],
headers: [{"content-type", "application/json"}],
body: "{\"url\":\"https://httpbin.org/get\"}",
status: 200,
opts: [],
__module__: nil,
__client__: nil
}Version 1.14
# tesla_1.14_mock.exs
Mix.install([
{:jason, "~> 1.4"},
{:tesla, "~> 1.14.0"}
])
Application.ensure_all_started(:tesla)
Application.put_env(:tesla, :adapter, Tesla.Mock)
defmodule MyAgent do
use Agent
def start_link(_arg) do
Agent.start_link(fn -> Tesla.get!("https://httpbin.org/get") end, name: __MODULE__)
end
end
Tesla.Mock.mock(fn _ -> Tesla.Mock.json(%{"url" => "https://httpbin.org/get"}) end)
{:ok, _pid} = MyAgent.start_link([])
IO.inspect(:sys.get_state(MyAgent), label: "state")$ elixir tesla_1.14_mock.exs
** (EXIT from #PID<0.99.0>) an exception was raised:
** (Tesla.Mock.Error) There is no mock set for process #PID<0.9.0>.
Use Tesla.Mock.mock/1 to mock HTTP requests.
See https://github.com/teamon/tesla#testing
(tesla 1.14.1) lib/tesla/mock.ex:206: Tesla.Mock.call/2
(tesla 1.14.1) lib/tesla.ex:75: Tesla.execute!/3
(elixir 1.17.3) lib/agent/server.ex:8: Agent.Server.init/1
(stdlib 5.2.3.2) gen_server.erl:980: :gen_server.init_it/2
(stdlib 5.2.3.2) gen_server.erl:935: :gen_server.init_it/6
(stdlib 5.2.3.2) proc_lib.erl:241: :proc_lib.init_p_do_apply/3Metadata
Metadata
Assignees
Labels
No labels