From d4fbb04622ca2be705e2c476ead1d0044427524b Mon Sep 17 00:00:00 2001 From: Isaac Yonemoto Date: Mon, 30 Mar 2020 01:07:15 -0700 Subject: [PATCH] Mocks should define a behaviour (#90) --- lib/mox.ex | 1 + test/mox_test.exs | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/lib/mox.ex b/lib/mox.ex index 8ef5ffb..a69fa1e 100644 --- a/lib/mox.ex +++ b/lib/mox.ex @@ -351,6 +351,7 @@ defmodule Mox do validate_behaviour!(behaviour) quote do + @behaviour unquote(behaviour) unquote(behaviour).module_info(:module) end end diff --git a/test/mox_test.exs b/test/mox_test.exs index 5a70b64..8b1742a 100644 --- a/test/mox_test.exs +++ b/test/mox_test.exs @@ -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