-
-
Notifications
You must be signed in to change notification settings - Fork 232
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
Feature/capture #97
Feature/capture #97
Conversation
I propose we use the matcher structure for this, as a query language. I'd rather see we build a history query API that we then can build these functions upon. For example, using the ETS match specification "language", the capture(Pos, {Mod, Func, Arity}, Args) -> % <- Note: Args instead of Arg
Results = meck_history:query(Mod, {Func, Args}),
case Pos of
last -> lists:last(Results)
...
end. Where Also, please do different pull requests for code cleanup stuff. This pull request should not have to be dependent on #96? |
This is an excellent idea! Since it is |
@eproxus I broaden the notion of Besides I changed the originally proposed interface of %% Given
meck:new(test, [non_strict]),
meck:expect(test, foo, 2, ok),
meck:expect(test, foo, 3, ok),
meck:expect(test, foo, 4, ok),
meck:expect(test, bar, 3, ok),
test:foo(1001, 2001, 3001, 4001),
test:bar(1002, 2002, 3002),
test:foo(1003, 2003, 3003),
test:bar(1004, 2004, 3004),
test:foo(1005, 2005),
test:foo(1006, 2006, 3006),
test:bar(1007, 2007, 3007),
test:foo(1008, 2008, 3008),
%% When/Then
?assertMatch(2001, meck:capture(first, test, foo, '_', 2)),
?assertMatch(2003, meck:capture(first, test, foo, 3, 2)),
?assertMatch(2005, meck:capture(first, test, foo, ['_', '_'], 2)),
?assertMatch(2006, meck:capture(first, test, foo, [1006, '_', '_'], 2)),
?assertMatch(2008, meck:capture(first, test, foo, ['_', '_', meck:is(hamcrest_matchers:greater_than(3006))], 2)),
%% Clean
meck:unload(). I decided to put history query changes aside for another pull request for this one starting to become rather big. |
By the way, it is one of the functions for history digging mentioned in #85. |
@eproxus Hey Adam, have you had a chance to take a look at this? |
@chernser It's true that I don't put as much time as needed on review the incoming changes from @horkhe. My main problem has been the feature vs lines of code ratio which in my opinion is too small, and in many cases I haven't had the time to suggest improvements, because the pull request have most often been huge. That being said, you are free to use @horkhe's fork if you want. This is also a great way for me to determine whether these features are actually needed by users! (So I appreciate the feedback that this is a feature you want). @horkhe You told me that this feature makes the concept of |
Before this pull request Out of 300 lines of code the majority are just comments and unit tests, and also some renaimings to make things allign better with the broader |
@horkhe Make sense. :-) What are your opinions or removing the When you mentioned earlier that you put history query changes aside, did you mean mimicking the ETS query API when it comes to deciding return values? I think that API is more powerful than the current arity/argument index API. |
Sure we can raise error at the spot without {ok, ...} wrappers. I will change that. |
Get a feel for the API and let me know what you think. I just had the feeling that getting rid of repeated okays all over the code would be nice. :-) |
As for the ETS query the current API uses args_spec() to define arguments of the call to capture so effectively you have the same power as ETS query - you can specify partially defined arguments. |
Is not that what you was asking for? |
I was thinking of defining the return values, like in
Enhancement with limit (or pos):
Could also possibly return just the element |
Now I get you. The main problem with that is that args_spec() allows specifying matchers as arguments, and the The main use case for this feature is to capture such things as Pids and functions that you can later on send a message or call to respectively to continue the test flow. So all is needed is the entire value. If other cases On the other hand it might be useful to capture several arguments with one call. Though I would suggested to make API a little less verbose (after all we do not need everything that comes with ETS. I also would suggest that we relese it in another pull request as another version of the suggested [2006, 3006] = meck:capture(first, test, foo, [blah, '$1', '$2'], ['$1', '$2']) |
It returns just value (not wrapped in {ok, ...} and fails with error:not_found if the expected call has not happened.
I adjusted the pull request description and another my comment to reflect the API change. |
👍 |
Introduces capability to capture an argument a mocked function was called with. It is particularly useful to obtain references to internal funs passed as callbacks to mocked functions.