Skip to content

Fix Ruby-version-dependent hash literal syntax in generated specs#589

Merged
dblock merged 1 commit into
slack-ruby:masterfrom
dblock:fix-hash-inspect-format-drift
Jul 5, 2026
Merged

Fix Ruby-version-dependent hash literal syntax in generated specs#589
dblock merged 1 commit into
slack-ruby:masterfrom
dblock:fix-hash-inspect-format-drift

Conversation

@dblock

@dblock dblock commented Jul 5, 2026

Copy link
Copy Markdown
Collaborator

Problem

The scheduled automated API update workflow (PR #578 being an example) occasionally produced spurious diffs flipping hash literal syntax back and forth between:

{data: ["data"]}

and

{:data=>["data"]}

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.erb relied on implicit string interpolation of a real Hash object (#{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_literal helper to method_spec.erb that explicitly renders Hash/Array values as source text using the modern key: value syntax (valid since Ruby 1.9, well within this gem's supported Ruby 2.7+ range) instead of relying on Hash#inspect. This makes generated output deterministic and independent of the Ruby version used to run rake 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 master content already matches this deterministic format and future regenerations will no longer drift.

Co-authored-by: Copilot 223556219+Copilot@users.noreply.github.com

@github-actions

github-actions Bot commented Jul 5, 2026

Copy link
Copy Markdown

Danger Report

No issues found.

View run

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>
@dblock dblock force-pushed the fix-hash-inspect-format-drift branch from f2adcb1 to 253307e Compare July 5, 2026 19:19
@dblock dblock merged commit 7552a74 into slack-ruby:master Jul 5, 2026
10 checks passed
@coveralls

Copy link
Copy Markdown

Coverage Report for CI Build 28751995911

Warning

Build has drifted: This PR's base is out of sync with its target branch, so coverage data may include unrelated changes.
Quick fix: rebase this PR. Learn more →

Coverage remained the same at 91.075%

Details

  • Coverage remained the same as the base build.
  • Patch coverage: No coverable lines changed in this PR.
  • No coverage regressions found.

Uncovered Changes

No uncovered changes found.

Coverage Regressions

No coverage regressions found.


Coverage Stats

Coverage Status
Relevant Lines: 5759
Covered Lines: 5245
Line Coverage: 91.07%
Coverage Strength: 110.66 hits per line

💛 - Coveralls

@dblock dblock deleted the fix-hash-inspect-format-drift branch July 5, 2026 19:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants