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

Add deny/3 #143

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
15 changes: 14 additions & 1 deletion guides/Telemetry.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@
- `[:hammox, :verify_on_exit!, :start]`
- metadata:
- `context`: Context passed into `verify_on_exit!` setup function
- `[:hammox, :deny, :start]`
- metadata:
- `mock`: Name of the mock/behaviour
- `function_name`: Name of the function that is being mocked
- `arity`: The arity of the function

## Stop Events
- `[:hammox, :expect, :stop]`
Expand All @@ -66,6 +71,11 @@
- metadata: none
- `[:hammox, :verify_on_exit!, :stop]`
- metadata: none
- `[:hammox, :deny, :stop]`
- metadata:
- `mock`: Name of the mock/behaviour
- `func`: Name of the function that is being mocked
- `arity`: The arity of the function

## Exception Events
- `[:hammox, :expect, :exception]`
Expand All @@ -88,6 +98,8 @@
- metadata: none
- `[:hammox, :verify_on_exit!, :exception]`
- metadata: none
- `[:hammox, :deny, :exception]`
- metadata: none

## Example Code
All supported events can be generated and attached to with the following code:
Expand All @@ -103,7 +115,8 @@
:fetch_typespecs,
:cache_put,
:stub,
:verify_on_exit!
:verify_on_exit!,
:deny
]

Enum.map(event_list, fn event ->
Expand Down
14 changes: 14 additions & 0 deletions lib/hammox.ex
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,20 @@ defmodule Hammox do
)
end

@doc """
See [Mox.deny/3](https://hexdocs.pm/mox/Mox.html#deny/3).
"""
def deny(mock, function_name, arity) do
Telemetry.span(
[:hammox, :deny],
%{mock: mock, function_name: function_name, arity: arity},
fn ->
result = Mox.deny(mock, function_name, arity)
{result, %{}}
end
)
end

@doc """
See [Mox.stub/3](https://hexdocs.pm/mox/Mox.html#stub/3).
"""
Expand Down
2 changes: 1 addition & 1 deletion mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ defmodule Hammox.MixProject do

defp deps do
[
{:mox, "~> 1.0"},
{:mox, "~> 1.2"},
{:ordinal, "~> 0.1"},
{:telemetry, "~> 1.0"},
{:ex_doc, "~> 0.21", only: :dev, runtime: false},
Expand Down