MECK
ADAM LINDBERG     @eproxus    hello@alind.io
1000 lines of code
18 contributors
2 years old
meck:new(atom()).
1> meck:new(foo, [non_strict]).ok2> foo:module_info(exports).[{module_info,0},{module_info,1}]
3> meck:expect(foo, bar, 0, baz).ok4> foo:bar().baz
5> meck:expect(foo, bar, fun() -> baz end).ok6> foo:bar().baz
6> meck:expect(foo, bar, [1, true], baz).ok7> foo:bar(1, true).baz8> foo:bar(1, false).** exception error: no function cla...
11> meck:expect(foo, bar, [1, _], baz).ok12> foo:bar(1,true).baz13> foo:bar(1,false).baz
28> meck:expect(foo, bar, [{[1, true], baz},                           {[1, false], qux}]).ok29> foo:bar(1,true).baz30> fo...
[func_clause_spec()]
[func_clause_spec()]
[{args_spec(), ret_spec()}]
[{[any() | _], ret_spec()}]
[{[any() | _], ret_spec()}]
[{[any() | _], ret_spec()}]  any() | meck:val(any())     meck:loop([any()])     meck:seq([any()]) meck:raise(Class, Reason)
meck:expect(foo, bar, [    {[read],   meck:seq([a, b, c, eof])},    {[_],    meck:loop([1, 2, 3])}])
79> [foo:bar(read) || _ <- lists:seq(1, 5)].[1,2,3,eof,eof]80> [foo:bar(write) || _ <- lists:seq(1, 5)].[1,2,3,1,2]
32> meck:expect(foo, bar,        fun() ->            meck:exception(error, epic_fail)        end).ok33> foo:bar().** excep...
9> meck:new(string, [passthrough, no_link,                     unstick]).ok10> string:len("meck").4
?assert(meck:validate(foo)).
?assert(meck:called(foo, bar, [1, _])).
?assertEqual(4,    meck:num_calls(foo, bar, [1, _])).
81> meck:history(foo).[{<0.153.0>,{foo,bar,[]},baz}, {<0.153.0>,{foo,bar,[]},baz}, {<0.153.0>,{foo,bar,[1,true]},baz}, {<0...
meck:new(atom(), [option()]).
meck:new(atom(), [option()]).
meck:new(atom(), [option()]).        passthrough
meck:new(atom(), [option()]).    no_passthrough_cover
meck:new(atom(), [option()]).   {stub_all, ret_spec()}
meck:new(atom(), [option()]).          no_link
meck:new(atom(), [option()]).          unstick
meck:new(atom(), [option()]).         no_history
meck:new(atom(), [option()]).         non_strict
meck:new(atom(), [option()]).    {spawn_opt, [any()]}
meck:delete(foo, bar, 1).
meck:unload(foo).
QUESTIONS?http://github.com/eproxus/meck
Upcoming SlideShare
Loading in …5
×

Meck

1,015 views

Published on

An introduction to Meck, the mocking framework for Erlang, given at the Erlang User Group meeting on the 5th of November in Berlin.

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,015
On SlideShare
0
From Embeds
0
Number of Embeds
10
Actions
Shares
0
Downloads
7
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • Meck

    1. 1. MECK
    2. 2. ADAM LINDBERG @eproxus hello@alind.io
    3. 3. 1000 lines of code
    4. 4. 18 contributors
    5. 5. 2 years old
    6. 6. meck:new(atom()).
    7. 7. 1> meck:new(foo, [non_strict]).ok2> foo:module_info(exports).[{module_info,0},{module_info,1}]
    8. 8. 3> meck:expect(foo, bar, 0, baz).ok4> foo:bar().baz
    9. 9. 5> meck:expect(foo, bar, fun() -> baz end).ok6> foo:bar().baz
    10. 10. 6> meck:expect(foo, bar, [1, true], baz).ok7> foo:bar(1, true).baz8> foo:bar(1, false).** exception error: no function clause matching test:bar(1,false)
    11. 11. 11> meck:expect(foo, bar, [1, _], baz).ok12> foo:bar(1,true).baz13> foo:bar(1,false).baz
    12. 12. 28> meck:expect(foo, bar, [{[1, true], baz}, {[1, false], qux}]).ok29> foo:bar(1,true).baz30> foo:bar(1,false).qux
    13. 13. [func_clause_spec()]
    14. 14. [func_clause_spec()]
    15. 15. [{args_spec(), ret_spec()}]
    16. 16. [{[any() | _], ret_spec()}]
    17. 17. [{[any() | _], ret_spec()}]
    18. 18. [{[any() | _], ret_spec()}] any() | meck:val(any()) meck:loop([any()]) meck:seq([any()]) meck:raise(Class, Reason)
    19. 19. meck:expect(foo, bar, [ {[read], meck:seq([a, b, c, eof])}, {[_], meck:loop([1, 2, 3])}])
    20. 20. 79> [foo:bar(read) || _ <- lists:seq(1, 5)].[1,2,3,eof,eof]80> [foo:bar(write) || _ <- lists:seq(1, 5)].[1,2,3,1,2]
    21. 21. 32> meck:expect(foo, bar, fun() -> meck:exception(error, epic_fail) end).ok33> foo:bar().** exception error: epic_fail in function foo:bar/0
    22. 22. 9> meck:new(string, [passthrough, no_link, unstick]).ok10> string:len("meck").4
    23. 23. ?assert(meck:validate(foo)).
    24. 24. ?assert(meck:called(foo, bar, [1, _])).
    25. 25. ?assertEqual(4, meck:num_calls(foo, bar, [1, _])).
    26. 26. 81> meck:history(foo).[{<0.153.0>,{foo,bar,[]},baz}, {<0.153.0>,{foo,bar,[]},baz}, {<0.153.0>,{foo,bar,[1,true]},baz}, {<0.153.0>,{foo,bar,[1,false]}, error,function_clause, [{foo,bar,[1,false]},...]}, {<0.167.0>,{foo,bar,[1,true]},baz}, {<0.167.0>,{foo,bar,[1,false]},baz}, ...]
    27. 27. meck:new(atom(), [option()]).
    28. 28. meck:new(atom(), [option()]).
    29. 29. meck:new(atom(), [option()]). passthrough
    30. 30. meck:new(atom(), [option()]). no_passthrough_cover
    31. 31. meck:new(atom(), [option()]). {stub_all, ret_spec()}
    32. 32. meck:new(atom(), [option()]). no_link
    33. 33. meck:new(atom(), [option()]). unstick
    34. 34. meck:new(atom(), [option()]). no_history
    35. 35. meck:new(atom(), [option()]). non_strict
    36. 36. meck:new(atom(), [option()]). {spawn_opt, [any()]}
    37. 37. meck:delete(foo, bar, 1).
    38. 38. meck:unload(foo).
    39. 39. QUESTIONS?http://github.com/eproxus/meck

    ×