Skip to content

Commit

Permalink
Formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
whatyouhide committed Mar 16, 2024
1 parent 8e25ccf commit adfbf88
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions lib/req/test.ex
Original file line number Diff line number Diff line change
Expand Up @@ -212,18 +212,25 @@ defmodule Req.Test do
def stub(stub_name) do
case NimbleOwnership.fetch_owner(@ownership, callers(), stub_name) do
{:ok, owner} when is_pid(owner) ->
result =
NimbleOwnership.get_and_update(@ownership, owner, stub_name, fn
%{expectations: [value | rest]} = map ->
{{:ok, value}, put_in(map[:expectations], rest)}

result = NimbleOwnership.get_and_update(@ownership, owner, stub_name, fn
%{expectations: [value | rest]} = map -> {{:ok, value}, put_in(map[:expectations], rest)}
%{stub: value} = map -> {{:ok, value}, map}
%{expectations: []} = map -> {{:error, :no_expectations_and_no_stub}, map}
end)
%{stub: value} = map ->
{{:ok, value}, map}

%{expectations: []} = map ->
{{:error, :no_expectations_and_no_stub}, map}
end)

case result do
{:ok, {:ok, value}} -> value
{:ok, {:error, :no_expectations_and_no_stub}} -> raise "no stub or expectations for #{inspect(stub_name)}"
end
{:ok, {:ok, value}} ->
value

{:ok, {:error, :no_expectations_and_no_stub}} ->
raise "no stub or expectations for #{inspect(stub_name)}"
end

:error ->
raise "cannot find stub #{inspect(stub_name)} in process #{inspect(self())}"
Expand All @@ -248,7 +255,7 @@ defmodule Req.Test do
"""
def stub(stub_name, value) do
NimbleOwnership.get_and_update(@ownership, self(), stub_name, fn map_or_nil ->
{:ok, put_in((map_or_nil || %{}), [:stub], value)}
{:ok, put_in(map_or_nil || %{}, [:stub], value)}
end)
end

Expand Down

0 comments on commit adfbf88

Please sign in to comment.