Skip to content

Mock a module only from the perspective of a specific module #34

Open
eproxus opened this Issue Jul 25, 2011 · 4 comments

2 participants

@eproxus
Owner
eproxus commented Jul 25, 2011

It should be possible to mock a module only from the perspective of another specific module. This would allow mocking the file module for example, which is not possible due to its use from the code module (resulting in a crash when replacing the module).

Implementation Proposal

Instead of replacing and compiling the mock module globally, a mocked module is created with another name than the original. Then all calls to the original module in the module under test is replaced with calls to the new mocked module.

@horkhe
horkhe commented Oct 23, 2012

calls to the original module in the module under test is replaced with calls to the new mocked module

How is it possible to do that? Parse transform?

@eproxus
Owner
eproxus commented Oct 23, 2012

The idea was to actually change the code under test instead, by replacing all calls to that module with a call to the mock module.

With the downside of course that you change the code under test, which for some kinds of verification might be too much.

@horkhe
horkhe commented Oct 23, 2012

I though that we might achieve that by forcing all processes in the Erlang VM to apply save_calls flag and whenever a mocked module is called inspect the caller history and see from what module the call was made. I even asked a question on StackOverflow about that. But it seems there is no easy programmatic way to do that.

@eproxus
Owner
eproxus commented Oct 23, 2012

Possibly also too heavy-weight.

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.