Questions tagged [meck]

With meck you can easily mock modules in Erlang. You can also perform some basic validations on the mocked modules, such as making sure no unexpected exceptions occurred or looking at the call history.

With meck you can easily mock modules in Erlang. You can also perform some basic validations on the mocked modules, such as making sure no unexpected exceptions occurred or looking at the call history.


Features

  • Automatic renaming and restoration of original modules
  • Automatic backup and restore of cover data
  • Changing return values using sequences and loops of static values
  • Pass through: use functions from the original module
  • Mock is linked to the creating process (disable with no_link)
  • Complete call history showing calls, results and exceptions
  • Mocking of sticky modules (using the option unstick)
  • Throwing of expected exceptions that keeps the module valid

Resources

19 questions
0
votes
0 answers

How to properly mock riakc_pb_socket with meck?

Using Erlang R16B02, riakc 2.0.0 and meck 0.82: When trying to mock riakc_pb_socket in my unit tests it blows up. Here's what I get: > erl -pa ebin deps/*/ebin Erlang R16B02 (erts-5.10.3) [source-b44b726] [64-bit] [smp:2:2] [async-threads:10]…
Khorkrak
  • 3,911
  • 2
  • 27
  • 37
0
votes
1 answer

Writing Meck testcases for gen_tcp function

Here is a simple IRC bot module written by Erlang: IRC Bot Could someone helps me write the testcase for the function connect and parse_line with MECK connect(Host, Port) -> {ok, Sock} = gen_tcp:connect(Host, Port, [{packet, line}]), …
0
votes
1 answer

Correct way to use meck with foreach

I am using meck to test my gen_server mymodule. In particular I use meck to mock httpc following the instructions provided here. Here is some code I extracted from my test: do_some_tests_() -> {foreach, fun start/0, fun stop/1, [fun…
user601836
  • 3,215
  • 4
  • 38
  • 48
0
votes
1 answer

Meck behaving strangely for multiple mocked modules

I have following module -module(bhavcopy_downloader). -export([download/2]). download(From, SaveTo) -> {ok, {{Status, _}, _, Body}} = lhttpc:request(From, "GET", [], infinity), case Status of 200 -> file:write(SaveTo, Body), …
Suhas
  • 7,919
  • 5
  • 34
  • 54
1
2