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

Mocks should behaviour #90

Merged
merged 2 commits into from
Mar 30, 2020
Merged
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
1 change: 1 addition & 0 deletions lib/mox.ex
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,7 @@ defmodule Mox do
validate_behaviour!(behaviour)

quote do
@behaviour unquote(behaviour)
unquote(behaviour).module_info(:module)
end
end
Expand Down
11 changes: 11 additions & 0 deletions test/mox_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,17 @@ defmodule MoxTest do
assert {:docs_v1, _, :elixir, "text/markdown", %{"en" => "hello world"}, _, _} =
Code.fetch_docs(MyMockWithStringModuledoc)
end

test "has behaviours of what it mocks" do
defmock(OneBehaviourMock, for: Calculator)
assert one_behaviour = OneBehaviourMock.__info__(:attributes)
assert {:behaviour, [Calculator]} in one_behaviour

defmock(MultiBehaviourMock, for: [Calculator, ScientificCalculator])
assert two_behaviour = MultiBehaviourMock.__info__(:attributes)
assert {:behaviour, [Calculator]} in two_behaviour
assert {:behaviour, [ScientificCalculator]} in two_behaviour
end
end

describe "expect/4" do
Expand Down