Skip to content

chore(deps): update dependency webmock to v4 - #648

Open
renovate[bot] wants to merge 1 commit into
stagingfrom
renovate/webmock-4.x
Open

renovate[bot] wants to merge 1 commit into
stagingfrom
renovate/webmock-4.x

Conversation

@renovate

@renovate renovate Bot commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

This PR contains the following updates:

Package Change Age Confidence
webmock (changelog) '~> 3.41' → '~> 4.3' age confidence

Release Notes

bblimke/webmock (webmock)

v4.3.0

Compare 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 raises WebMock::NetConnectNotAllowedError unless a stub matches. disallow: accepts the same matchers as allow:.

    Thanks to sandfortw for the suggestion

  • Fix RequestStub#then silently ignoring its block (#​1037)

    Previously, stub.then { |s| s.with(query: {page: "1"}) } ignored the block. The stub now requires page=1, so a request without it no longer matches. With a block, then returns the block's result. Without a block, it still chains responses as before.

  • Fix Excon splitting stubbed chunks when Transfer-Encoding is ["gzip", "chunked"]

    WebMock now keeps transfer encodings in the order you specify. With body_chunks: ["ab", "cd"] and Excon's chunk_size: 1, the streaming callback now receives "ab" and "cd". Previously it received four single bytes.

v4.2.0

Compare 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 the read_body block in one call. With to_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 to response_block. Reading the whole body returns "hello" with any adapter.

v4.1.0

Compare Source

  • Match request headers with hash_including and hash_excluding (#​942)

    with(headers: hash_including("Authorization")) now matches any request with an Authorization header. Use hash_excluding("Authorization") to match requests without that header. Both WebMock's and RSpec's matchers work here. Previously, using either matcher raised NoMethodError.

    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_auth raises ArgumentError. To match basic authentication, include the expected Authorization header value in hash_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_including or hash_excluding as a multipart body pattern raises ArgumentError.

    Net::HTTP forms sent with set_form are recorded without a body, so any body pattern raises ArgumentError for those requests. Typhoeus and Curb pass WebMock the form fields, so patterns that expect the raw multipart body won't match.

v4.0.0

Compare 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_json still matches with(body: {id: 1}), and VCR records and replays as before.

Breaking change

  • Ruby 3.0 or later, and crack 0.4.6 or later. On Ruby 2.6 and 2.7, Bundler keeps installing WebMock 3.x. On JRuby, 4.0 needs JRuby 9.4 or later. If your Gemfile pins crack below 0.4.6, loosen the pin.

Fixes that can fail a spec

  • Stubs that didn't do what they said now fail where they are declared. A bare to_return crashed on the first matching request, to_raise(:timeout) returned a 200 instead of raising, and to_return(status: 404) { ... } dropped the status. These now raise ArgumentError.

  • Request bodies that aren't valid JSON no longer match a hash pattern. A request that sent {a: 1} as JSON matched with(body: {a: 1}), although a real server would reject it. JSON from to_json isn'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 request now gets the response while Net::HTTP reads it, instead of after WebMock has read all of it.

Statuses such as :ok still print the deprecation warning added in 3.39.0, rather than raising. Use a number, such as 200.

If a spec fails

Stub declarations
  • For an empty 200 response, leave off a bare to_return, or give it a response, such as to_return(status: 200). to_return and to_return_json with no arguments, an empty list or empty **options raise ArgumentError, and so does a nil response, which raised NoMethodError before.
  • Give to_raise an exception class, an exception or a message, such as to_raise(StandardError). Use to_timeout for a timeout.
  • Give to_return either responses or a block, such as to_return { |request| {status: 404, body: "x"} }.

The same checks apply to and_return, and_return_json and and_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_including or hash_excluding no longer matches:

  • a request body that isn't valid JSON, such as {a: 1} or {'a': 1}. Send {a: 1}.to_json instead.
  • a value the old parser read differently. The body {"amount":1e+20} matches {amount: 1e20}, not {amount: "1e+20"}.

A lambda or matcher in a body pattern now gets only the value JSON.parse returns, such as the Float 1.0e+20. One that calls a String method on it, such as start_with?, raises NoMethodError, 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. So response.read_body { |chunk| ... } got the body in one piece, and response.decode_content = true in the block left a gzip body compressed. Now the block gets the response while Net::HTTP reads it, as without WebMock, unless an after_request callback for Net::HTTP, such as VCR's, needs the whole body first. A callback registered with except: [:net_http] doesn't.

Code that relied on WebMock reading the body first can now fail, as it does without WebMock:

  • Another request on the same connection, sent inside the block or after breaking out of it before the body is read, can fail. Send it after the block returns, or on another connection.
  • read_body with a block, called after a request made with a block has returned, raises IOError. Call it inside the block.
  • When the connection drops while the body is read, the net-http versions in Ruby 3.4 and later raise instead of retrying. That includes http.get without a block of your own, since it passes one to request. The net-http versions in Ruby 3.3 and earlier retry a GET and run the block again, even when the block raised IOError.

v3.42.0

Compare Source

  • Fix VCR failing to replay responses recorded with the auto_inflate feature of the http gem (#​1154)

    Previously, for a real request made with HTTP.use(:auto_inflate), after_request callbacks got the inflated body together with the Content-Encoding: gzip header of the compressed one. VCR, hooked into WebMock, recorded both, and replaying the cassette raised Zlib::DataError: incorrect header check, because the feature tried to inflate the body again. With VCR's decode_compressed_response option, recording raised Zlib::GzipFile::Error instead.

    Callbacks now get the inflated body without the Content-Encoding header, as they do for a body that Net::HTTP inflates. A Content-Length header, 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 caching feature of http 6. Callbacks get those as before.

    Cassettes recorded with older versions that have the Content-Encoding header on an inflated body still fail. Record them again, or remove that header from their responses. Their Content-Length is still that of the compressed body.


Configuration

📅 Schedule: (in timezone Europe/Amsterdam)

  • Branch creation
    • At any time (no schedule defined)
  • Automerge
    • At any time (no schedule defined)

🚦 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.


  • If you want to rebase/retry this PR, check this box

This PR was generated by Mend Renovate. View the repository job log.

@renovate renovate Bot added the dependencies Pull requests that update a dependency file label Nov 29, 2026
@coderabbitai

coderabbitai Bot commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

Important

Review skipped

Bot user detected.

To trigger a single review, invoke the @coderabbitai review command.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 1643bffd-d8f2-4866-bf62-e5d2249285bd

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@codecov

codecov Bot commented Nov 29, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (18447d8) to head (34767a0).

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@renovate
renovate Bot force-pushed the renovate/webmock-4.x branch 2 times, most recently from 03e10fb to bbc164d Compare December 4, 2026 10:12
@renovate
renovate Bot force-pushed the renovate/webmock-4.x branch from bbc164d to 34767a0 Compare December 4, 2026 22:33

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dependencies Pull requests that update a dependency file

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants