Skip to content

Commit

Permalink
mix format
Browse files Browse the repository at this point in the history
  • Loading branch information
josevalim committed Aug 10, 2023
1 parent 70acee8 commit 43f4de1
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 19 deletions.
2 changes: 1 addition & 1 deletion lib/mox.ex
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ defmodule Mox do
when the allowance happens. In such a case, you might specify the allowance
as a function in the form `(-> pid())`. This function would be resolved late,
at the very moment of dispatch. If the function does not return an existing
PID, it will fail `Mox.UnexpectedCallError`.
PID, it will fail `Mox.UnexpectedCallError`.
### Global mode
Expand Down
80 changes: 62 additions & 18 deletions test/mox_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -354,21 +354,30 @@ defmodule MoxTest do
expect(SciCalcOnlyMock, :exponent, fn x, y -> x * y end)

error = assert_raise(Mox.VerificationError, &verify!/0)
assert error.message =~ ~r"expected CalcMock.add/2 to be invoked once but it was invoked 0 times"
assert error.message =~ ~r"expected SciCalcOnlyMock.exponent/2 to be invoked once but it was invoked 0 times"

assert error.message =~
~r"expected CalcMock.add/2 to be invoked once but it was invoked 0 times"

assert error.message =~
~r"expected SciCalcOnlyMock.exponent/2 to be invoked once but it was invoked 0 times"

CalcMock.add(2, 3)
error = assert_raise(Mox.VerificationError, &verify!/0)
refute error.message =~ ~r"expected CalcMock.add/2"
assert error.message =~ ~r"expected SciCalcOnlyMock.exponent/2 to be invoked once but it was invoked 0 times"

assert error.message =~
~r"expected SciCalcOnlyMock.exponent/2 to be invoked once but it was invoked 0 times"

SciCalcOnlyMock.exponent(2, 3)
verify!()

# Adding another expected call makes verification fail again
expect(CalcMock, :add, fn x, y -> x + y end)
error = assert_raise(Mox.VerificationError, &verify!/0)
assert error.message =~ ~r"expected CalcMock.add/2 to be invoked 2 times but it was invoked once"

assert error.message =~
~r"expected CalcMock.add/2 to be invoked 2 times but it was invoked once"

refute error.message =~ ~r"expected SciCalcOnlyMock.exponent/2"
end

Expand All @@ -380,14 +389,21 @@ defmodule MoxTest do
expect(SciCalcOnlyMock, :exponent, fn x, y -> x * y end)

error = assert_raise(Mox.VerificationError, &verify!/0)
assert error.message =~ ~r"expected CalcMock.add/2 to be invoked once but it was invoked 0 times"
assert error.message =~ ~r"expected SciCalcOnlyMock.exponent/2 to be invoked once but it was invoked 0 times"

assert error.message =~
~r"expected CalcMock.add/2 to be invoked once but it was invoked 0 times"

assert error.message =~
~r"expected SciCalcOnlyMock.exponent/2 to be invoked once but it was invoked 0 times"

Task.async(fn -> SciCalcOnlyMock.exponent(2, 4) end)
|> Task.await()

error = assert_raise(Mox.VerificationError, &verify!/0)
assert error.message =~ ~r"expected CalcMock.add/2 to be invoked once but it was invoked 0 times"

assert error.message =~
~r"expected CalcMock.add/2 to be invoked once but it was invoked 0 times"

refute error.message =~ ~r"expected SciCalcOnlyMock.exponent/2"

Task.async(fn -> CalcMock.add(5, 6) end)
Expand All @@ -397,7 +413,10 @@ defmodule MoxTest do

expect(CalcMock, :add, fn x, y -> x + y end)
error = assert_raise(Mox.VerificationError, &verify!/0)
assert error.message =~ ~r"expected CalcMock.add/2 to be invoked 2 times but it was invoked once"

assert error.message =~
~r"expected CalcMock.add/2 to be invoked 2 times but it was invoked once"

refute error.message =~ ~r"expected SciCalcOnlyMock.exponent/2"
end
end
Expand All @@ -412,18 +431,27 @@ defmodule MoxTest do
expect(SciCalcOnlyMock, :exponent, fn x, y -> x * y end)

error = assert_raise(Mox.VerificationError, fn -> verify!(CalcMock) end)
assert error.message =~ ~r"expected CalcMock.add/2 to be invoked once but it was invoked 0 times"

assert error.message =~
~r"expected CalcMock.add/2 to be invoked once but it was invoked 0 times"

refute error.message =~ ~r"expected SciCalcOnlyMock.exponent/2"

error = assert_raise(Mox.VerificationError, fn -> verify!(SciCalcOnlyMock) end)
assert error.message =~ ~r"expected SciCalcOnlyMock.exponent/2 to be invoked once but it was invoked 0 times"

assert error.message =~
~r"expected SciCalcOnlyMock.exponent/2 to be invoked once but it was invoked 0 times"

refute error.message =~ ~r"expected CalcMock.add/2"

CalcMock.add(2, 3)
verify!(CalcMock)

error = assert_raise(Mox.VerificationError, fn -> verify!(SciCalcOnlyMock) end)
assert error.message =~ ~r"expected SciCalcOnlyMock.exponent/2 to be invoked once but it was invoked 0 times"

assert error.message =~
~r"expected SciCalcOnlyMock.exponent/2 to be invoked once but it was invoked 0 times"

refute error.message =~ ~r"expected CalcMock.add/2"

SciCalcOnlyMock.exponent(2, 3)
Expand All @@ -432,7 +460,10 @@ defmodule MoxTest do

expect(CalcMock, :add, fn x, y -> x + y end)
error = assert_raise Mox.VerificationError, fn -> verify!(CalcMock) end
assert error.message =~ ~r"expected CalcMock.add/2 to be invoked 2 times but it was invoked once"

assert error.message =~
~r"expected CalcMock.add/2 to be invoked 2 times but it was invoked once"

refute error.message =~ ~r"expected SciCalcOnlyMock.exponent/2"
verify!(SciCalcOnlyMock)
end
Expand All @@ -446,29 +477,42 @@ defmodule MoxTest do
expect(SciCalcOnlyMock, :exponent, fn x, y -> x * y end)

error = assert_raise(Mox.VerificationError, fn -> verify!(CalcMock) end)
assert error.message =~ ~r"expected CalcMock.add/2 to be invoked once but it was invoked 0 times"

assert error.message =~
~r"expected CalcMock.add/2 to be invoked once but it was invoked 0 times"

refute error.message =~ ~r"expected SciCalcOnlyMock.exponent/2"

error = assert_raise(Mox.VerificationError, fn -> verify!(SciCalcOnlyMock) end)
assert error.message =~ ~r"expected SciCalcOnlyMock.exponent/2 to be invoked once but it was invoked 0 times"

assert error.message =~
~r"expected SciCalcOnlyMock.exponent/2 to be invoked once but it was invoked 0 times"

refute error.message =~ ~r"expected CalcMock.add/2"

Task.async(fn -> CalcMock.add(2, 3) end)
|> Task.await()

verify!(CalcMock)

error = assert_raise(Mox.VerificationError, fn -> verify!(SciCalcOnlyMock) end)
assert error.message =~ ~r"expected SciCalcOnlyMock.exponent/2 to be invoked once but it was invoked 0 times"

assert error.message =~
~r"expected SciCalcOnlyMock.exponent/2 to be invoked once but it was invoked 0 times"

refute error.message =~ ~r"expected CalcMock.add/2"

SciCalcOnlyMock.exponent(2, 3)
verify!(CalcMock)
verify!(SciCalcOnlyMock)

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

error = assert_raise(Mox.VerificationError, &verify!/0)
assert error.message =~ ~r"expected CalcMock.add/2 to be invoked 2 times but it was invoked once"

assert error.message =~
~r"expected CalcMock.add/2 to be invoked 2 times but it was invoked once"

refute error.message =~ ~r"expected SciCalcOnlyMock.exponent/2"

verify!(SciCalcOnlyMock)
Expand Down

0 comments on commit 43f4de1

Please sign in to comment.