Repository navigation
chore(deps): update dependency webmock to v4 - #648
Open
renovate[bot] wants to merge 1 commit into
Open
renovate[bot] wants to merge 1 commit into
renovate[bot] wants to merge 1 commit into
Conversation
Contributor
|
Important Review skippedBot user detected. To trigger a single review, invoke the
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## staging #648 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 198 198
Lines 3027 3027
=========================================
Hits 3027 3027 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
renovate
Bot
force-pushed
the
renovate/webmock-4.x
branch
2 times, most recently
from
December 4, 2026 10:12
03e10fb to
bbc164d
Compare
renovate
Bot
force-pushed
the
renovate/webmock-4.x
branch
from
December 4, 2026 22:33
bbc164d to
34767a0
Compare
This branch has not been deployed
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.
This PR contains the following updates:
'~> 3.41'→'~> 4.3'Release Notes
bblimke/webmock (webmock)
v4.3.0Compare Source
Allow real requests except to destinations listed in
disallow:(#1058)WebMock.allow_net_connect!(disallow: ["billing.example.com"])lets tests reach other hosts. When WebMock intercepts a request to the billing host, it raisesWebMock::NetConnectNotAllowedErrorunless a stub matches.disallow:accepts the same matchers asallow:.Thanks to sandfortw for the suggestion
Fix
RequestStub#thensilently ignoring its block (#1037)Previously,
stub.then { |s| s.with(query: {page: "1"}) }ignored the block. The stub now requirespage=1, so a request without it no longer matches. With a block,thenreturns the block's result. Without a block, it still chains responses as before.Fix Excon splitting stubbed chunks when
Transfer-Encodingis["gzip", "chunked"]WebMock now keeps transfer encodings in the order you specify. With
body_chunks: ["ab", "cd"]and Excon'schunk_size: 1, the streaming callback now receives"ab"and"cd". Previously it received four single bytes.v4.2.0Compare Source
Add support for
body_chunks:to specify which chunks a streaming HTTP client receives from a stub (#629)With
to_return(body: "hello"), Net::HTTP yields"hello"to theread_bodyblock in one call. Withto_return(body_chunks: ["hel", "lo"]), it calls the block twice, first with"hel"and then with"lo". This lets you test how your code handles a message split across two reads.Curb and Typhoeus also deliver the chunks to
on_body, and Excon delivers them toresponse_block. Reading the whole body returns"hello"with any adapter.v4.1.0Compare Source
Match request headers with
hash_includingandhash_excluding(#942)with(headers: hash_including("Authorization"))now matches any request with an Authorization header. Usehash_excluding("Authorization")to match requests without that header. Both WebMock's and RSpec's matchers work here. Previously, using either matcher raisedNoMethodError.Header names follow the same rules as in a plain header hash. Ordinary values such as strings and numbers compare as text. You can also match a value with a regexp, for example
hash_including("Authorization" => /^Bearer /), or with another matcher that implements===.For repeated headers, supply an array of strings. Combining a header matcher with
basic_authraisesArgumentError. To match basic authentication, include the expected Authorization header value inhash_including.Match raw multipart request bodies (#623)
You can now match an uploaded filename with
with(body: /filename="report\.pdf"/), even when the file contains binary data. A regexp can match part of the raw multipart body. A string matches the entire body byte for byte. A lambda receives the raw body.WebMock still doesn't parse multipart form fields, so using a hash, an array,
hash_includingorhash_excludingas a multipart body pattern raisesArgumentError.Net::HTTP forms sent with
set_formare recorded without a body, so any body pattern raisesArgumentErrorfor those requests. Typhoeus and Curb pass WebMock the form fields, so patterns that expect the raw multipart body won't match.v4.0.0Compare Source
4.0 requires Ruby 3.0 or later. Its other changes fix behaviour that was wrong in 3.x, so a spec fails only if it passed because of one of them. A typical test suite needs no changes: a stub such as
stub_request(:get, url).to_return(body: "ok")works as before, a request that sends{id: 1}.to_jsonstill matcheswith(body: {id: 1}), and VCR records and replays as before.Breaking change
Fixes that can fail a spec
Stubs that didn't do what they said now fail where they are declared. A bare
to_returncrashed on the first matching request,to_raise(:timeout)returned a 200 instead of raising, andto_return(status: 404) { ... }dropped the status. These now raiseArgumentError.Request bodies that aren't valid JSON no longer match a hash pattern. A request that sent
{a: 1}as JSON matchedwith(body: {a: 1}), although a real server would reject it. JSON fromto_jsonisn't affected. Before upgrading, run your specs on 3.42.0 and fix any JSON body warnings it prints.Real Net::HTTP requests behave as without WebMock. This only matters if your specs make real requests through Net::HTTP that aren't stubbed or recorded with VCR. The block given to
requestnow gets the response while Net::HTTP reads it, instead of after WebMock has read all of it.Statuses such as
:okstill print the deprecation warning added in 3.39.0, rather than raising. Use a number, such as200.If a spec fails
Stub declarations
to_return, or give it a response, such asto_return(status: 200).to_returnandto_return_jsonwith no arguments, an empty list or empty**optionsraiseArgumentError, and so does anilresponse, which raisedNoMethodErrorbefore.to_raisean exception class, an exception or a message, such asto_raise(StandardError). Useto_timeoutfor a timeout.to_returneither responses or a block, such asto_return { |request| {status: 404, body: "x"} }.The same checks apply to
and_return,and_return_jsonandand_raise.Thanks to Daniel Pepper
JSON request bodies (#432)
3.41.0 started reading JSON request bodies with
JSON.parse, and fell back to WebMock's old JSON parser with a deprecation warning. 4.0 drops the old parser, so a body declared as a hash, an array,hash_includingorhash_excludingno longer matches:{a: 1}or{'a': 1}. Send{a: 1}.to_jsoninstead.{"amount":1e+20}matches{amount: 1e20}, not{amount: "1e+20"}.A lambda or matcher in a body pattern now gets only the value
JSON.parsereturns, such as the Float1.0e+20. One that calls a String method on it, such asstart_with?, raisesNoMethodError, which fails the request even when another stub would match. 3.42.0 warns about such a lambda only when the old reading matched.When the only reason a stub doesn't match is that the request body isn't valid JSON, the failure message now says so and quotes the parser's error, unless body diffs are hidden with
WebMock.hide_body_diff!.Real Net::HTTP requests (#742)
Previously, with real requests allowed, WebMock read the whole response before calling the block given to
request. Soresponse.read_body { |chunk| ... }got the body in one piece, andresponse.decode_content = truein the block left a gzip body compressed. Now the block gets the response while Net::HTTP reads it, as without WebMock, unless anafter_requestcallback for Net::HTTP, such as VCR's, needs the whole body first. A callback registered withexcept: [:net_http]doesn't.Code that relied on WebMock reading the body first can now fail, as it does without WebMock:
read_bodywith a block, called after a request made with a block has returned, raisesIOError. Call it inside the block.http.getwithout a block of your own, since it passes one torequest. The net-http versions in Ruby 3.3 and earlier retry a GET and run the block again, even when the block raisedIOError.v3.42.0Compare Source
Fix VCR failing to replay responses recorded with the
auto_inflatefeature of thehttpgem (#1154)Previously, for a real request made with
HTTP.use(:auto_inflate),after_requestcallbacks got the inflated body together with theContent-Encoding: gzipheader of the compressed one. VCR, hooked into WebMock, recorded both, and replaying the cassette raisedZlib::DataError: incorrect header check, because the feature tried to inflate the body again. With VCR'sdecode_compressed_responseoption, recording raisedZlib::GzipFile::Errorinstead.Callbacks now get the inflated body without the
Content-Encodingheader, as they do for a body that Net::HTTP inflates. AContent-Lengthheader, when the response has one, gives the size of the inflated body. The response the client returns is unchanged, and so are the headers of a response with an empty body, such as one to a HEAD request.A cassette recorded this way replays the response with those headers, while the real response keeps the headers of the compressed body.
This doesn't cover a client that inflates with a subclass of the feature, or responses returned by the
cachingfeature ofhttp6. Callbacks get those as before.Cassettes recorded with older versions that have the
Content-Encodingheader on an inflated body still fail. Record them again, or remove that header from their responses. TheirContent-Lengthis still that of the compressed body.Configuration
📅 Schedule: (in timezone Europe/Amsterdam)
🚦 Automerge: Disabled by config. Please merge this manually once you are satisfied.
♻ Rebasing: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.
🔕 Ignore: Close this PR and you won't be reminded about this update again.
This PR was generated by Mend Renovate. View the repository job log.