Skip to content

Fix json >= 3.0 compatibility - #115

Open
dblock wants to merge 1 commit into
masterfrom
fix-json-3-compat
Open

Fix json >= 3.0 compatibility#115
dblock wants to merge 1 commit into
masterfrom
fix-json-3-compat

Conversation

@dblock

@dblock dblock commented Sep 12, 2026

Copy link
Copy Markdown
Owner

Description

Fixes #113.

Faraday's built-in :json response middleware calls JSON.parse(body, options) positionally. The json gem 3.0 changed JSON.parse to accept options as keyword arguments only, so this raised ArgumentError: wrong number of arguments (given 2, expected 1), surfaced by Faraday as Faraday::ParsingError.

This replaces the built-in middleware with Strava::Web::JsonResponse, a subclass overriding #parse to call JSON.parse(body) with a single argument, which works with both json < 3.0 and >= 3.0.

Now that the gem no longer depends on Faraday's buggy behavior:

Testing

  • Full spec suite passes under the default Gemfile, gemfiles/json_2.gemfile, and gemfiles/json_3.gemfile (previously 18 failures under json 3.x).
  • Added spec/strava/web/json_response_spec.rb covering the new middleware's #parse method.
  • Rubocop passes cleanly via gemfiles/rubocop.gemfile.

Replace Faraday's built-in :json response middleware, which calls
JSON.parse(body, options) positionally, with Strava::Web::JsonResponse,
a subclass that calls JSON.parse(body) with a single argument. This
works with both json < 3.0 and json >= 3.0, which made options keyword-only.

Also uncomments the json-3 appraisal in CI now that it passes, and
removes the json ~> 2.3 pin from the Gemfile since it's no longer needed.

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

Copy link
Copy Markdown

Danger Report

No issues found.

View run

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.

Faraday::ParsingError with json gem >= 3.0 (ArgumentError: wrong number of arguments)

1 participant