Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix verify_on_exit!/1 with nimble_ownership #152

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/mox.ex
Original file line number Diff line number Diff line change
Expand Up @@ -804,7 +804,9 @@ defmodule Mox do
verify_mock_or_all!(self(), mock)
end

defp verify_mock_or_all!(owner_pid, mock_or_all) do
# Made public for testing.
@doc false
def verify_mock_or_all!(owner_pid, mock_or_all) do
all_expectations = NimbleOwnership.get_owned(@this, owner_pid, _default = %{}, @timeout)

pending =
Expand Down
19 changes: 19 additions & 0 deletions test/mox_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -640,6 +640,25 @@
end
end

describe "verify_on_exit!/0 with errors" do
test "raises if the mocks are not called" do

Check failure on line 644 in test/mox_test.exs

View workflow job for this annotation

GitHub Actions / test (1.11, 21.3)

test verify_on_exit!/0 with errors raises if the mocks are not called (MoxTest)

Check failure on line 644 in test/mox_test.exs

View workflow job for this annotation

GitHub Actions / test (1.16, 26.2, lint)

test verify_on_exit!/0 with errors raises if the mocks are not called (MoxTest)
pid = self()

# This replicates exactly what verify_on_exit/1 does, but it adds an assertion
# in there. There's no easy way to test that something gets raised in an on_exit
# callback.
ExUnit.Callbacks.on_exit(Mox, fn ->
assert_raise Mox.VerificationError, fn ->
verify_mock_or_all!(pid, :all)
end
end)

set_mox_private()

expect(CalcMock, :add, fn x, y -> x + y end)
end
end

describe "stub/3" do
test "allows repeated invocations" do
in_all_modes(fn ->
Expand Down
Loading