Repository navigation
Load the http_rb adapter only where HTTP::Client is defined - #1139
Merged
Merged
Conversation
Other libraries define a top-level HTTP with a VERSION, and require "http" can load one of them. WebMock then took it for the http gem and raised NameError aliasing HTTP::Client#perform, so WebMock couldn't be loaded at all.
thoran
force-pushed
the
http-rb-adapter-needs-http-client
branch
from
October 18, 2026 15:52
9ef7cf3 to
d7f80d3
Compare
bblimke
added a commit
that referenced
this pull request
Nov 18, 2026
Sort indexed keys by number and then by text, so "01" and "1" always come out in the same order, as they did with the old text sort. sort_by is not stable, so the order of such keys depended on the order of the query. Check for digit keys with \A and \z, so a key with digits on just one of its lines stays a hash key instead of becoming index 0. Drop the redundant defined?(HTTP) from the http_rb adapter guard, use map in dehash, and add specs for indexed hashes in a query, for keys with leading zeros and for a key spanning lines. Document both PRs in the CHANGELOG, including what to do with stubs that list indexed values in the old order.
Owner
|
Thank you @thoran! This is released in 3.35.0. |
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.
The http_rb adapter is loaded wherever there's an
HTTP::VERSION, but other gems define a top-levelHTTPwith aVERSIONtoo. When one of them is loaded,require "webmock"fails with:so WebMock can't be used at all, not even with Net::HTTP.
The gem I ran into this with is the
http.rbgem on RubyGems (https://rubygems.org/gems/http.rb). Despite the name, it isn't thehttpgem (httprb/http) this adapter is for. It's a separate, smaller library, built on Net::HTTP, which WebMock's Net::HTTP adapter already covers. It defines a top-levelHTTPmodule with aVERSION, but noHTTP::Client. Its load file islib/http.rb, so wherever it's installed the adapter's ownrequire "http"can load it, and WebMock then fails whatever order things are required in. (Up to 1.6.0 the file waslib/HTTP.rb, whichrequire "http"found only on a case-insensitive filesystem such as macOS's default.) With any gem like it, WebMock fails where that gem is loaded first.This adds
defined?(HTTP::Client), the class the adapter patches, to the guard. Where the http gem is loaded,HTTP::Clientis always defined, sincerequire "http"loads it, so nothing changes there.The spec loads WebMock in a separate Ruby process with a stand-in
http.rbahead of it on the load path, which definesHTTP::VERSIONand nothing else, and checks that WebMock loads and doesn't define the adapter. Without the change, that process raises the NameError above.I haven't added a CHANGELOG entry, since those seem to be written at release time.