Skip to content

Commit

Permalink
handle {:shared_owner, owner} in __fetch_plug__ (#387)
Browse files Browse the repository at this point in the history
  • Loading branch information
braidonw committed Jul 17, 2024
1 parent 26b688d commit 0ed6d09
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
11 changes: 11 additions & 0 deletions lib/req/test.ex
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,17 @@ defmodule Req.Test do
raise "no mock or stub for #{inspect(name)}"
end

{:shared_owner, owner} when is_pid(owner) ->
result = Req.Test.Ownership.get_owned(@ownership, owner)[name]

case result do
%{stub: value} ->
value

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

:error ->
raise "cannot find mock/stub #{inspect(name)} in process #{inspect(self())}"
end
Expand Down
10 changes: 10 additions & 0 deletions test/req/test_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@ defmodule Req.TestTest do
|> Task.await()

assert Req.Test.__fetch_plug__(:foo) == {MyPlug, [2]}

Req.Test.stub(:bar, {SharedPlug, [1]})
Req.Test.set_req_test_to_shared()

Task.async(fn ->
assert Req.Test.__fetch_plug__(:bar) == {SharedPlug, [1]}
end)
|> Task.await()
after
Req.Test.set_req_test_to_private()
end

describe "expect/3" do
Expand Down

0 comments on commit 0ed6d09

Please sign in to comment.