Skip to content

Commit

Permalink
Mocks should define a behaviour (#90)
Browse files Browse the repository at this point in the history
  • Loading branch information
ityonemo authored Mar 30, 2020
1 parent e2b0ca4 commit d4fbb04
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
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

0 comments on commit d4fbb04

Please sign in to comment.