Fix Ruby-version-dependent hash literal syntax in generated specs#589
Merged
Merged
Conversation
Danger ReportNo issues found. |
Ruby 3.4 changed Hash#inspect's default rendering of symbol keys from the hash-rocket form (:foo=>1) to the modern shorthand (foo: 1). The method_spec.erb template relied on implicit string interpolation of a real Hash object when building the "encodes ... as json" test's params, so the literal syntax emitted into generated spec files depended on whichever Ruby version ran the generator. Since CI's scheduled update_api.yml workflow pins Ruby 3.2, automated PRs could flip-flop between hash-rocket and shorthand syntax on every run, causing spurious diffs. Add a ruby_literal helper that explicitly renders Hash/Array values as source text using the modern key: value syntax (valid since Ruby 1.9, well within our supported Ruby 2.7+ range), so generated output is identical regardless of the Ruby version used to run rake slack:web:api:update. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Signed-off-by: Daniel (dB.) Doubrovkine <dblock@dblock.org>
f2adcb1 to
253307e
Compare
Coverage Report for CI Build 28751995911Warning Build has drifted: This PR's base is out of sync with its target branch, so coverage data may include unrelated changes. Coverage remained the same at 91.075%Details
Uncovered ChangesNo uncovered changes found. Coverage RegressionsNo coverage regressions found. Coverage Stats
💛 - Coveralls |
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.
Problem
The scheduled automated API update workflow (PR #578 being an example) occasionally produced spurious diffs flipping hash literal syntax back and forth between:
and
Root cause
Ruby 3.4 changed
Hash#inspect's default rendering of symbol keys from the hash-rocket form (:foo=>1) to the modern shorthand (foo: 1).lib/slack/web/api/templates/method_spec.erbrelied on implicit string interpolation of a realHashobject (#{val}) when building the "encodes ... as json" test's params, so the literal syntax emitted into generated spec files depended on whichever Ruby version ran the generator..github/workflows/update_api.yml's scheduled job pins Ruby 3.2, while a contributor running the rake task locally may have a newer Ruby, so regenerated PRs would alternate style depending on who/what last ran it.Fix
Add a
ruby_literalhelper tomethod_spec.erbthat explicitly rendersHash/Arrayvalues as source text using the modernkey: valuesyntax (valid since Ruby 1.9, well within this gem's supported Ruby 2.7+ range) instead of relying onHash#inspect. This makes generated output deterministic and independent of the Ruby version used to runrake slack:web:api:update.Verified by regenerating all endpoints/specs/commands with this template change: only the fix itself changed (no other endpoint or spec file differs), confirming the current
mastercontent already matches this deterministic format and future regenerations will no longer drift.Co-authored-by: Copilot 223556219+Copilot@users.noreply.github.com