Skip to content

Instantly share code, notes, and snippets.

@josephwilk
Last active December 18, 2015 21:09
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save josephwilk/5845416 to your computer and use it in GitHub Desktop.
Save josephwilk/5845416 to your computer and use it in GitHub Desktop.
defmodule Punk do
def hip? do
true
end
def hop? do
hip?
end
end
fact "mock with an arguments" do
:meck.new(Punk, [:passthrough])
:meck.expect(Punk, :hip?, fn -> false end)
Punk.hip? |> falsey
#Passes
Punk.hop? |> falsey
#Fails with: (UndefinedFunctionError) undefined function: Punk_meck_original.hop?/0
end
@josephwilk
Copy link
Author

To replicate:

Ensure Elixir is installed & atleast Erlang R16

brew install elixir

Then run:

git clone -b nested_mock git@github.com:josephwilk/amrita.git && cd amrita && MIX_ENV=test mix deps.get && mix test

Failing test: https://github.com/josephwilk/amrita/blob/nested_mock/test/integration/meck_test.exs

Using Meck through Elixir I'm not sure if its some interop issue, my misunderstanding or something else.

Removing the ? had no effect.

@eproxus
Copy link

eproxus commented Jun 23, 2013

I get the following error:

$ mix test
** (CompileError) /Users/alind/Dropbox/Code/amrita/test/integration/meck_test.exs:44: function provided/2 undefined
    :meck.__info__(:macros)
    src/elixir_dispatch.erl:301: :elixir_dispatch.get_optional_macros/1
    src/elixir_dispatch.erl:155: :elixir_dispatch.expand_require/6
    src/elixir_dispatch.erl:99: :elixir_dispatch.dispatch_require/6
    lists.erl:1329: :lists.mapfoldl/3
    lists.erl:1330: :lists.mapfoldl/3
    src/elixir_translator.erl:62: :elixir_translator.translate_each/2
    src/elixir_translator.erl:610: :elixir_translator.translate_arg/2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment