Repository navigation
Conversation
Defines normalized JSON and excluded keys so the code and future design discussions share one meaning for each term.
Normalization was spread over Helpers, Exclusion and BeJsonEql, and the key sort that makes equivalence work hid inside Exclusion#exclude_keys. As a result normalize_json kept source key order while be_json_eql compared sorted keys, and include_json compared Ruby values instead of normalized JSON. JsonSpec::Normalization now owns dropping excluded keys, sorting keys and generating text. The normalize helpers and both matchers go through it, so they agree on what equivalent means. Exclusion shrinks to the per-matcher key set.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
🤖 Normalization was spread over
Helpers,ExclusionandBeJsonEql, and the key sort that makes equivalence work was hidden insideExclusion#exclude_keys. As a result "normalized JSON" meant two different things:normalize_jsonkept source key order whilebe_json_eqlcompared sorted keys, andinclude_jsoncompared Ruby values rather than normalized JSON.What changes
JsonSpec::Normalization.normalize(ruby, excluded_keys: [])owns dropping excluded keys, sorting keys and generating text.normalize_json,generate_normalized_json,be_json_eqlandinclude_jsonall go through it, so they agree on what "equivalent" means.JsonSpec::Exclusionshrinks to the per-matcher set of excluded keys.CONTEXT.md, a short domain glossary defining "normalized JSON" and "excluded keys".Behaviour changes
All are listed in
CHANGELOG.mdunder 2.0.0 unless noted.normalize_jsonandgenerate_normalized_jsonnow sort object keys. They still exclude nothing.include_jsoncompares normalized JSON element by element, likebe_json_eql. An integer no longer matches an equal float ([10.0]does not include10), and a non-string expected value against a JSON string fails instead of raisingTypeError.JsonSpec::Exclusion.exclude_keysandexclude_key?are removed, and the module no longer extends itself. It was never documented.allow_nan: true, becauseJSON.parsereads numbers too large for a float (1e400) asInfinity. Without itinclude_jsonwould raise on any document containing such a number. This also meansbe_json_eqlandnormalize_jsonno longer raiseJSON::GeneratorErroron such input, andnormalize_json("1e400")returnsInfinity, which is not valid JSON. Open question for review: keep this, or narrow it toinclude_jsononly.Testing
bundle exec rakepasses locally on Ruby 4.0.2: 129 examples, 53 scenarios.spec/json_spec/normalization_spec.rbtests the module at its interface. New specs cover key sorting in the helpers, theinclude_jsonequality changes, overflowing numbers, and requiring onlyjson_spec/helpers.require "json_spec/helpers"raisingNameError, and the overflowing-number crash); both are fixed with regression specs. The review was not re-run after the fixes.