Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

meck:unload is undefined? #72

Closed
ostinelli opened this Issue · 3 comments

2 participants

@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.

@eproxus
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.

@eproxus eproxus closed this
@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.

@eproxus
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.