Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
Fix diff output when a fuzzy finder anything is inside an expected hash #599
Fix diff output when a fuzzy finder anything is inside an expected hash #599
Changes from 9 commits
b993756
4c22e70
048ac0a
c3e9ea9
416cd49
0dea769
31f086e
dd7a4c7
938096c
7046659
6b7ff69
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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.
What I really liked about your previous changes was the potential to get rid of the recursive check and the safely_flatten method.
No pressure, as this is not the goal of the pr, but it would be a nice bonus to fixing the issue. And a performance improvement in theory.
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 understand, it would be nice to get rid of that recursivity. You can count on me to brainstorm on another PR or submit a proposal to fix that issue. I am enjoying reading and getting my hands on this project, and once this PR is finished (by finished I mean either merged or closed (if you and the other maintainers believe the changes I'm proposing here are too risky, or not worth doing them)) I'd like to propose some changes to make the
BuiltIn::Change
matcher class diffable when it tries to match a Hash inrspec-expectations
repo... but that's another story.About your concern with
safely_flatten
, that method was introduced ~10 years ago. Does anyone still knows why that method is there? I think its purpose is not only to check in a one method call whether all the arguments are notProc
, but along withno_numbers?
to makeDiffer
work with deep down nested arrays insideactual
andexpected
vars. If we stick with my previous change, we can make the method faster, but we may loose theDiffer
feature to diff deep down nested arrays in a seamlessly way.Just some brainstorming and ramble here: Is it worth to keep that recursivity? when an
expected
andactual
vars with deep nested arrays are submitted as input toDiffer
, is worth to display a big diff output? are big diff strings useful when you have to scroll down pages of information? or a diff string is useful only when it shows the exact difference and a little bit of context? Maybe the answers to these questions will pop up when we will see such diff strings... I don't know the answer.On the project I am currently working on, when I'm testing the actual and expected values of a hash with nested hashes inside, I've found is useful to strip my actual hash of its nested objects in my test set-up, and inside an
aggregate_failures
block use oneexpect(...)...
sentence for the main hash, and for each nested object use an extraexpect(...)...
sentence. That's a nice workaround instead of testing a big hash in a singleexpect(...)...
sentence and expect a single diff to show me -everything- I want to see (the idea behind #596 )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 can’t tell of the top of my head with certainty, but I can’t recall if nested hashes are (usefully) diffed.
I’d rather simplify the code if no spec fails.
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.
Now when I look at this, this is indeed and improvement to
-anything_key +anything_key
we had.But do we need a potentially huge value here? An uuid is fine, but what about a 5kb json-like thing?
Most certainly if we’ve
anything
ed it in the test, we don’t care what’s inside, including the diff?@JonRowe does this make sense?
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.
Are you concerned by the case a 5kb json-like thing would be copied into the
expected -> anything
value? that will definitively be a performance issue. Would it be worth doing the change? Is there a way we can make sure the 5kb json-like thing will be a shallow copy? Maybe a shallow copy will mitigate the performance issue.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.
Maybe a shallow copy will not impact memory ram consumption. But what about CPU time? does
diff_as_object
iterates theactual
andexpected
vars regardless of their.object_id
? or it checks theobject_id
and if they match it will cease any iteration?Another question:
rspec-support
module should be allowed to mutateexpected
vars? regardless they will be later on return them to their original state? My proposed changes on this PR are a hacky way to fold noise when the developers useanything
fuzzy matcher on their hash, I understand this may not be allowed to do here.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.
Apparently, a 5kb json-like thing will impact CPU time ONLY if the matcher fails.
STEP 1 and STEP 2 will get the string representation of 5kb json-like thing in two different strings. STEP 3 will perform the comparison of both strings. This will be an expensive operation because both strings will be huge. In contrast, without the changes on this PR, comparing the string representation of this 5kb json-like thing with
anything
fuzzy matcher would have been easy-peasyAFAIK,
RSpec::Support::Differ
is called when an expectation matcher fails AND the expectation matcher responds to diffable?. If the matcher does not responds to diffable,expected
andactual
vars are assignednil
andRSpec::Support::Differ
will not perform any action at all.My assessment is this will impact performance only when the test fails and the developer is using a matcher that produces an output-diff. But this is my assessment about performance, I still don't know the answer to: should
rspec-support
module be allowed to mutateexpected
vars in the developer test bench (ie, his_spec.rb
files)? orrspec-support
should remain a "pure" read-only module?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 think @pirj's concern was about larger diffs, but as things should be identical the differ will often not print anything at all
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.
Identical - yes. But if it’s neighbouring with the difference, like the ‘anything_key’ here on line 567, and it is big, i would prefer to see the literal “anything” to be printed rather than 5kb of json.