Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
eproxus opened this issue Jul 25, 2011 · 5 comments
Closed

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

eproxus opened this issue Jul 25, 2011 · 5 comments

Comments

@eproxus
Copy link
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
Copy link
Contributor

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
Copy link
Owner Author

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
Copy link
Contributor

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
Copy link
Owner Author

eproxus commented Oct 23, 2012

Possibly also too heavy-weight.

@eproxus eproxus modified the milestones: 1.0, 2.0+ Nov 21, 2016
@eproxus
Copy link
Owner Author

eproxus commented Nov 21, 2016

Closing and documenting in the wiki instead: https://github.com/eproxus/meck/wiki#feature-ideas

Please comment here if you have information or requests to add, and/or want to discuss a PR or possible implementation proposal.

@eproxus eproxus closed this as completed Nov 21, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants