Skip to content

Check Faraday::Connection#ssl with to_hash in the client spec - #799

Merged
pboling merged 1 commit into
ruby-oauth:mainfrom
iMacTia:faraday-ssl-to-hash
Nov 27, 2026
Merged

pboling merged 1 commit into
ruby-oauth:mainfrom
iMacTia:faraday-ssl-to-hash

Conversation

@iMacTia

@iMacTia iMacTia commented Nov 26, 2026

Copy link
Copy Markdown

Faraday 2.16 builds its options classes, Faraday::SSLOptions included, on a new Faraday::BaseOptions class instead of Struct, and drops most of the Struct API. An ecosystem test of the 2.16 beta found that one spec here calls empty? on connection.ssl, so it fails on Faraday main:

OAuth2::Client#initialize leaves Faraday::Connection#ssl unset
  expected #<Faraday::SSLOptions (empty)> to respond to `empty?`

This PR checks connection.ssl.to_hash instead. On every Faraday version from 0.17.3 to 2.16, to_hash leaves out members that are nil. So the spec still checks that no SSL option is set. The library code does not call empty?, so oauth2 itself works on Faraday 2.16.

Faraday adds empty? back for compatibility in lostisland/faraday#1746, so released versions of oauth2 keep passing. With this change, the spec no longer depends on it.

Tests

The full suite, on Ruby 4.0.9:

Faraday Result
2.15.1 643 examples, 0 failures
main (8160a12) with the members fix of lostisland/faraday#1746, without empty? 643 examples, 0 failures

🤖 Generated with Claude Code

Faraday 2.16 builds SSLOptions on a new BaseOptions class instead of
Struct, and drops most of the Struct API, `empty?` included. The spec
"leaves Faraday::Connection#ssl unset" calls `empty?` on the options,
so it fails on Faraday main.

`to_hash` leaves out members that are nil, on every Faraday version
from 0.17.3 to 2.16. So `ssl.to_hash` is empty when no SSL option is
set.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
iMacTia pushed a commit to lostisland/faraday that referenced this pull request Nov 26, 2026
These methods are back only for code written against the legacy
Options Structs. elastic-transport, oauth2 and ruby_llm are moving off
them (elastic/elastic-transport-ruby#134, ruby-oauth/oauth2#799,
crmne/ruby_llm#1857), but their released versions still call them. So
they stay for the whole 2.x series, like StructCompat.

The docs now say they go away in 3.0 and name the replacement. There
is no runtime warning yet.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
iMacTia added a commit to lostisland/faraday that referenced this pull request Nov 26, 2026
* fix: restore the members class method on the options classes

Converting the options classes to BaseOptions removed the class method
`members` that the legacy Struct provided. elastic-transport 8.6.0
calls `Faraday::SSLOptions.members` to check for `verify_hostname`, so
every client set up with `ca_fingerprint:` fails on its first request
with NoMethodError.

BaseOptions.members now returns a copy of MEMBERS. Every class
converted from a Struct (Env, ConnectionOptions, RequestOptions,
SSLOptions and ProxyOptions) answers it as before, and a caller that
changes the result does not change the class.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix: restore empty? on the options classes

Converting the options classes to BaseOptions removed `empty?`, which
the legacy Options Structs answered with "no member is set". oauth2
2.1.0 checks a new connection with
`expect(subject.connection.ssl).to be_empty`. On Faraday main that
spec fails, because SSLOptions no longer responds to `empty?`.

BaseOptions#empty? is true when every member is nil, as before. A
member set to false counts as set.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* fix: restore to_h on the options classes

Converting the options classes to BaseOptions removed `to_h`, which
the legacy Options Structs answered with every member, nil included.
ruby_llm 2.2.3 calls `to_h` on Faraday::Env and SSLOptions in three
transport specs, and they fail on Faraday main with NoMethodError.

BaseOptions#to_h returns every member and its value, like Struct#to_h,
and maps the pairs when given a block. Nested options stay objects,
and Env leaves out its custom members, as before. to_hash still leaves
out nil values and converts nested options.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

* docs: deprecate members, empty? and to_h on the options classes

These methods are back only for code written against the legacy
Options Structs. elastic-transport, oauth2 and ruby_llm are moving off
them (elastic/elastic-transport-ruby#134, ruby-oauth/oauth2#799,
crmne/ruby_llm#1857), but their released versions still call them. So
they stay for the whole 2.x series, like StructCompat.

The docs now say they go away in 3.0 and name the replacement. There
is no runtime warning yet.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
@pboling

pboling commented Nov 27, 2026

Copy link
Copy Markdown
Member

This is a great find. Thanks!

@pboling
pboling merged commit f0a9653 into ruby-oauth:main Nov 27, 2026
36 of 41 checks passed
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