Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

meck:unload is undefined? #72

Closed
ostinelli opened this Issue · 3 comments

2 participants

Roberto Ostinelli Adam Lindberg
Roberto Ostinelli

Using this module, and R15B01:

-module(example).
-compile(export_all).

get_config() ->
    mocked:myfun("test.cfg").

-ifdef(TEST).
-include_lib("eunit/include/eunit.hrl").

get_config_test_() ->
    meck:new(mocked),
    meck:expect(mocked, myfun, fun(Filename) -> ok end),
    ?_assertEqual(ok, get_config()),
    ?_assert(meck:validate(mocked)),
    meck:unload(mocked).
-endif.

Compiling and running tests:

1> c(example, [{d, 'TEST'}]).
example.erl:19: Warning: variable 'Filename' is unused
example.erl:20: Warning: a term is constructed, but never used
example.erl:21: Warning: a term is constructed, but never used
{ok,example}
12> example:test().           
undefined
*** test module not found ***
::ok

=======================================================
  Failed: 0.  Skipped: 0.  Passed: 0.
One or more tests were cancelled.
error

However, if I comment the line meck:unload(mocked). then test passes successfully.

Adam Lindberg
Owner

Sorry for the late reply. The issue occurs because the trailing underscore (get_config_test_) tells EUnit that the function is a test generator, not a test. EUnit then expects the function to return a list of tests instead.

Adam Lindberg eproxus closed this
Roberto Ostinelli

indeed, it's a generator. i guess then meck has to be used within a test. i haven't find anything clarifying that in docs.

thank you,

r.

Adam Lindberg
Owner

Meck is not tied to a specific test library or framework. It just has a functional API that you can use in any code, really.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.