Skip to content

Commit

Permalink
insert into ets
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelst authored and edgurgel committed Oct 28, 2024
1 parent 4f2ea6f commit 38ca27a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/mimic/server.ex
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ defmodule Mimic.Server do
:ets.insert(__MODULE__, {{allowed_pid, module}, actual_owner_pid})

[] ->
:ok
:ets.insert(__MODULE__, {{allowed_pid, module}, owner_pid})
end

{:reply, {:ok, module}, state}
Expand Down
25 changes: 25 additions & 0 deletions test/mimic_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -796,6 +796,31 @@ defmodule Mimic.Test do
assert mult_result == :stubbed
end

test "allows different processes to share mocks from parent process when allow is defined first" do
parent_pid = self()

child_pid =
spawn_link(fn ->
receive do
:call_mock ->
add_result = Calculator.add(1, 1)
mult_result = Calculator.mult(1, 1)
send(parent_pid, {:verify, add_result, mult_result})
end
end)

Calculator
|> allow(self(), child_pid)
|> expect(:add, fn _, _ -> :expected end)
|> stub(:mult, fn _, _ -> :stubbed end)

send(child_pid, :call_mock)

assert_receive {:verify, add_result, mult_result}
assert add_result == :expected
assert mult_result == :stubbed
end

test "doesn't raise if no expectation defined" do
child_pid = spawn_link(fn -> :ok end)

Expand Down

0 comments on commit 38ca27a

Please sign in to comment.