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