Skip to content

Commit 758623e

Browse files
author
Paulo Daniel Gonzalez
authored
Add warning to stub/3 (#169)
1 parent 89e22d7 commit 758623e

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

lib/mox.ex

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -597,6 +597,16 @@ defmodule Mox do
597597
stub(MockWeatherAPI, :get_temp, fn _loc -> {:ok, 30} end)
598598
599599
`stub/3` will overwrite any previous calls to `stub/3`.
600+
601+
> #### Warning {: .warning}
602+
>
603+
> `stub/3` does **not verify that a call occurred**.
604+
> If the code stops calling the stubbed function
605+
> (for example, after a refactor), the test will still pass.
606+
>
607+
> This can lead to unused stubs lingering in tests.
608+
> Always use `expect/3` when you want to ensure the
609+
> function is actually invoked.
600610
"""
601611
@spec stub(mock, atom(), function()) :: mock when mock: t()
602612
def stub(mock, name, code)

0 commit comments

Comments
 (0)