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
Rename Expectation.should_call
method to something more descriptive
#86
Comments
I agree that One of the main reasons why flexmock is a nice-to-use library is because the API lets you write mocks and spies in a very natural way, when you use chaining (something you could read as an English sentence.) So something like, "let me hook flexmock to something and now something should receive some call and I choose to return a mock, or something calls a function and I choose an expectation (optionally)". It reads somewhat naturally, such that That being said, I completely agree that this specific wording is not descriptive enough, especially when you look at it standalone without the context of reading a chain as a "natural sentence" and we should change it to something as such. But also, I think A few alternatives I could think of, for improving the API would be:
I prefer option 1, but think that option 2 could be a good alternative in case we want to avoid a bigger change to the API. To reason option 1 a bit, as an example,
reads like, "Hook flexmock on And,
reads like, "Hook flexmock on |
I agree with your opinion, and I really like flexmock(something).should_call_spy('function').with_args('a', 2).and_return(True) Maybe a better option would be to have a slight change in that manner: flexmock(something).should_call_spied('function').with_args('a', 2).and_return(True)
flexmock(something).should_call_mocked('function').with_args('a', 2).and_return(True) |
@adarshk7, I think it's hard to make the language always to flow naturally when the methods are chained. For example, I would not go that far that I would also rename @christophe-riolo, although Another idea I got is what if we rename # call to `method` is proxied and args 1 & 2 are passed to the proxied method.
flexmock(SomeClass).should_proxy('method').with_args(1, 2)
# call to `method` is proxied and the proxied method is expected to return True.
flexmock(SomeClass).should_proxy('method').and_return(True)
|
I don't like that it's so long either, but it's almost the same as |
I think there's a lot of work that needs to go into the API in this regard. Even though this warrants a lot more changes, I think the long term plan should be to make the difference between spies and mocks a lot clearer, so far as to separate the API and the underlying code. What I mean is that With that I understand this would truly be a very breaking change, so with this (or perhaps an even better plan) in mind, I think we should consider a bigger picture of a long term change and move along that path in increments. Where I mean that if we think "expect call and should return" sounds good, let's still change it to The same goes for the mock side of things as well. I also believe that this clear separation of concern will also help clarify the underlying code quite a bit. Additionally, I think with this approach I had these alternatives in mind |
Why not |
I think it would be good to rename
Expectation.should_call
to something more descriptive to distinguish it better fromExpectation.should_receive
. When I did code reviews or wrote tests myself I quite often accidentally usedshould_call
(spying) when I should have calledshould_receive
(mock) or vice versa.I suggest that we rename
should_call
toshould_call_spy
. Other suggestions that we discussed before included renaming both methods to something likecall_mock
andcall_spy
. However, I think it's better to make minimal breaking changes to the API.The text was updated successfully, but these errors were encountered: