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
7
votes
2 answers

How to mock objects in Erlang using Meck?

Okay, I'm using Meck and I'm lost. My first language (that I've been writing for about 7 months) is Ruby, so I can't seem to wrap my brain around Meck mocking yet. I do get Ruby mocking though. Hoping someone can help me. Also, I've only been…
Kelly
  • 619
  • 8
  • 18
5
votes
2 answers

How do I install meck with my Erlang project?

I created my first Erlang project. It's a simple secret code game. I'm trying to avoid OTP at all costs because it seems REALLY confusing and my mentor thought it wasn't necessary to use it this go- around. I have three folders: ebin src test I…
Kelly
  • 619
  • 8
  • 18
4
votes
1 answer

What's the point of meck:validate?

As a newcomer to meck, I've been putting together a test that shows the various features. I cannot, however, understand why a developer might call meck:validate. Here's my…
MrBlueSky
  • 728
  • 6
  • 20
4
votes
2 answers

Using meck to make multiple calls to the same method with the same arguments

I know that with ruby/rspec, you can do something like the following in order to receive different return values for the different calls made to the method: allow(double).to receive(:msg).and_return(value1, value2, value3) I've only been able to…
Tony Baik
  • 146
  • 11
3
votes
1 answer

What causes a "not mocked" error when using meck (Erlang)?

I'm a meck (and Erlang) newbie and I'm struggling a bit with meck. I'm getting the following error: =ERROR REPORT==== 27-Jan-2014::16:20:05 === Error in process <0.1825.0> with exit value: {{not_mocked,substatsDb}, …
Rich
  • 658
  • 1
  • 9
  • 18
2
votes
1 answer

How can I progressively set up a mock using Meck?

I would like to be able to progressively set up a mock (using Meck), so that expectations for different calls are set in different test setup functions. I thought merge_expects might do the trick. But I am seeing unexpected results:…
MrBlueSky
  • 728
  • 6
  • 20
2
votes
1 answer

Erlang Meck: How does one mock only a specific function clause?

Give a function with multiple clauses, I'd want to mock only a specific case and for every other input that would otherwise cause a 'function_clause' error, I'd want to have it handled by the original function. It's almost like a selective…
sa___
  • 363
  • 2
  • 12
2
votes
1 answer

ExUnit mocks get mixed up in their concurrency (async: false not working?)

While executing ExUnit.start, in each case, I prepare mocks by meck like bellow defmodule MyModule.FooTest do use ExUnit.Case, async: false # explicitly sync import :meck alias MyModule.Foo alias MyModule.Baz # to be mocked …
otiai10
  • 4,289
  • 5
  • 38
  • 50
2
votes
2 answers

Can meck mock erlang:exit?

I want this in a supervisor module: stop() -> exit(whereis(mousetrap_sup), kill). So a naïve test might do this: stop_invokes_exit_test() -> meck:new(erlang, [unstick, passthrough]), meck:expect(erlang, whereis, 1, a_pid), …
Don Branson
  • 13,631
  • 10
  • 59
  • 101
2
votes
1 answer

In Elixir, how to mock a function that was defined in a 'used' module?

I'm using meck and it works great in most cases. However, I encountered the following error: elixir (ErlangError) erlang error: {:undefined_function, {OAuth2.Strategy.AuthCode, :new, 2}} I found that :new was a function defined in OAuth2.Strategy's…
Gjaldon
  • 5,534
  • 24
  • 32
1
vote
2 answers

In Erlang's EUnit, assert that a function was called with an anonymous function

I have some code that looks like this: -module(ca_data). -export([delete_ca_data/1]). % ... delete_ca_data(N) when N < 1 -> ?NEGATIVE_ID_ERROR; delete_ca_data(N) -> util_db_generic:delete_object(ca_data, N, fun(_) -> ok end). % ... And I have…
distortedsignal
  • 370
  • 5
  • 17
1
vote
1 answer

How do I meck the same function with multiple sets of parameter values?

I'm trying to meck out a call to application:get_env, but I'm testing a function that calls it with two different sets of arguments. I setup two separate meck:expect calls like this, but when the function I'm testing tries to call…
Grant Winney
  • 65,241
  • 13
  • 115
  • 165
1
vote
1 answer

How to meck:expect a function with multiple arities

I have a function in a module which has multiple function clauses for the same function name but different function arities. Example: -module(module_name). -export([func/1, func/2, func/3]). func(N) -> N. func(N, K) -> N * K. func(N,…
Sergey Ovchinnik
  • 472
  • 4
  • 16
1
vote
1 answer

How to use meck in different ExUnit test file

I would like to use meck in different ExUnit test file. For example, [x_test.exs] def setup do :meck.new(Hoge, [:passthrough])  on_exit(fn -> :meck.unload end)  :ok end def teardown do :meck.unload end test "foo" do :meck.expect(Hoge, :foo,…
tamagohan2
  • 445
  • 4
  • 15
1
vote
1 answer

Meck doesnt allow my processes to garbage collect

Im using Meck to simulate the behavior of some external services i have, purely for the sake of load testing and profiling my system, But it is causing me some issues. basically I have lots of worker processes being spawned, which then timeout after…
Stowelly
  • 1,260
  • 2
  • 12
  • 31
1
2