Skip to content

4.1.0

Latest

Choose a tag to compare

@bblimke bblimke released this 03 Dec 09:33
  • 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.