-
-
Notifications
You must be signed in to change notification settings - Fork 159
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
Display matching invocations alongside expectations #394
Display matching invocations alongside expectations #394
Conversation
At first glance, this looks really promising. I'll try to do a full review as soon as I can, but it might not be for a couple of days. Thanks again for all your contributions - they are much appreciated! 😄 |
feddf29
to
4dea01a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've now reviewed the commits up to and including the "DRY up tests" commit, i.e. I haven't looked in detail at the commits where you move invocations into cardinality. In general it looks great and I'm really grateful for all your work on this.
I've made a number of suggestions in inline comments. I've reviewed the changes commit by commit and it looks as if some of the inline comments have been hidden by GitHub, because it doesn't really respect the commits within the review process.
I also have a couple more general suggestions:
-
It would be nice to add unit tests for the new classes you've introduced, e.g.
Invocation
,RaisedException
, etc. Presumably we could effectively move some of the existing unit tests into these new tests...? -
It would also be nice if the
#assert_invocations
method you extracted in the acceptance test was less brittle i.e. did not assert the existence of other lines of the failure messages particularly details of the expected method. I can see that we need at least one test to ensure the invocations are displayed in the correct position within the other lines, but maybe that could be done separately...?
I'm sorry I haven't yet looked at the later commits, but given that I've suggested a bunch of changes, I wondered if it might be easier to get this first part of the PR merged as a separate PR and then tackle the latter commits in another PR. What do you think?
If you'd prefer, I'd be happy to address my suggestions myself, but unless I hear otherwise, I'll work on the assumption that you'll make the changes yourself.
test/acceptance/display_matching_invocations_alongside_expectations_test.rb
Show resolved
Hide resolved
test/acceptance/display_matching_invocations_alongside_expectations_test.rb
Outdated
Show resolved
Hide resolved
test/acceptance/display_matching_invocations_alongside_expectations_test.rb
Outdated
Show resolved
Hide resolved
test/acceptance/display_matching_invocations_alongside_expectations_test.rb
Outdated
Show resolved
Hide resolved
test/acceptance/display_matching_invocations_alongside_expectations_test.rb
Show resolved
Hide resolved
test/acceptance/display_matching_invocations_alongside_expectations_test.rb
Show resolved
Hide resolved
Just to expand slightly on my review, I think the most pressing issues are handling the |
9dca773
to
ff8c3a3
Compare
Since an expectation can have multiple matching invocations, and an invocation can yield multiple times, we will need to remember the sequence of yields per invocation. Yields also don't correspond 1:1 with returned values or raised expectations. Therefore, remembering the results/effects of an invocation is best done by a different object.
This will allow the yields to be captured and remembered by the invocation
e056a78
to
f8e640a
Compare
previously the expected arguments were being displayed here (using Expectation#method_signature), but now the actual arguments are displayed
The tests were helpful for test-driving, but not all are needed due to overlap
f8e640a
to
9391c7e
Compare
Less state to maintain. Array#size is O(1), so should be fine performance-wise.
expectations test extract the assert invocations method. Note that the method is a bit fragile as it assumes a certain fixture, without which the calling test would fail.
Cardinality and invocations go hand-in-hand. So, the target is to move invocations to Cardinality.
Cardinality and invocations go hand-in-hand. So, the target is to move invocations to Cardinality.
The target is to encapsulate it inside Cardinality in a tell-don't-ask style.
The target is to encapsulate it inside Cardinality in a tell-don't-ask style.
expected hadn't quite sounded right because it also included allowed
This helps us avoid rescuing an exception raised by code elsewhere in the Mocha code. Also, enables us to handle the missed scenario where Expectaction#throws is called, 'coz without it, we'd need a generic way to catch any thrown tag and that might be quite awkward.
9391c7e
to
4e32c0c
Compare
@nitishr I see you've done a bunch more work on this. Let me know if/when you'd like me to review anything. And in particular whether you're happy with the idea of only merging the first half of this PR as a first step...? I'm also happy to take it off your hands now you've done all the hard work if you're fed up with it! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not fed up. I've addressed all your commit-based comments except where it was minor and too painful for me to fix using fixup and rebase.
I'm now gonna try to address your two general comments:
- unit tests for new classes
- make assert_invocations less brittle
I don't expect to make any more changes to non-test code, so feel free to review now if you'd like or wait until I'm done with the above 2 points.
As for breaking the PR up, while I'm not opposed to it, I'm not too keen to do the (what feels to me like) git gymnastics required to split unless not splitting is actually making the review harder for you (or you don't approve of the later changes). I see that the PR could be seen as two logically distinct pieces of work, but the oppositve view seems equally fair to me.
I'll commit my test changes to the same branch/PR, and you could decide if you wanna review and merge it in one go or two (or discard the cardinality-related changes altogether).
test/acceptance/display_matching_invocations_alongside_expectations_test.rb
Show resolved
Hide resolved
test/acceptance/display_matching_invocations_alongside_expectations_test.rb
Outdated
Show resolved
Hide resolved
test/acceptance/display_matching_invocations_alongside_expectations_test.rb
Show resolved
Hide resolved
test/acceptance/display_matching_invocations_alongside_expectations_test.rb
Show resolved
Hide resolved
checking that invocations follow 'satisfied expectations:' ensures the invocations are displayed in the correct position within the other lines
OK, I think I'm now done with this PR. I've made assert_invocations less brittle. I think that assertion as well as the whole test file could be further improved, but I don't have any bright ideas atm. As for unit tests for the new classes, I did write one for Invocation but decided to discard it because I thought it didn't do much more than to introduce an extra set of tests that're more coupled to the structure of the system than the acceptance tests. I understand that those unit tests would still be valuable to pinpoint the causes of failures more narrowly than the acceptance tests do. However, I think the risk of difficulty focusing on the cause of a failure isn't high enough to offset the cost of the unnecessary/redundant structural coupling between the implementation and unit tests. Also, upon reflection, I'm now much more open to splitting into 2 PRs if it makes it easier for you to review or manage as I noticed there's still a number of commits for you to review. However, I'll leave it to you to decide. |
Cool. I've created a new version of the branch to which I've done the following:
I still haven't yet reviewed the later cardinality-related commits. I plan to tackle that next or at least decide whether to merge the earlier commits first. |
I've had an initial look at the remaining commits. I'm not yet 100% convinced that the invocations belong "inside" the cardinality, but I need to have a bit more of a think about it. Rather than add review comments to this PR for the later commits, I've decided to get the first commits merged and then open a new PR with the remaining commits. |
First bunch of commits from #394. Co-authored-by: Nitish Rathi <[email protected]>
I've now merged the first set of commits in 00f0540. |
I've now opened a 2nd PR containing the other commits. Closing this one. |
Also handles Expectaction#throws scenario. PR: #410 Second bunch of commits from #394. Co-authored-by: Nitish Rathi <[email protected]>
As suggested in #178