including: Partially match request query parameters or request bodies

View source: R/partial.R

includingR Documentation

Partially match request query parameters or request bodies

Description

For use inside wi_th()

Usage

including(x)

excluding(x)

Arguments

x

(list) a list; may support other classes in the future

Value

same as x, but with two attributes added:

  • partial_match: always TRUE

  • partial_type: the type of match, one of include or exclude

Headers

Matching on headers already handles partial matching. That is, wi_th(headers = list(Fruit = "pear")) matches any request that has any request header that matches - the request can have other request headers, but those don't matter as long as there is a match. These helpers (including/excluding) are needed for query parameters and bodies because by default matching must be exact for those.

Examples

including(list(foo = "bar"))
excluding(list(foo = "bar"))

# get just keys by setting values as NULL
including(list(foo = NULL, bar = NULL))

# in a stub
req <- stub_request("get", "https://httpbin.org/get")
req

## query
wi_th(req, query = list(foo = "bar"))
wi_th(req, query = including(list(foo = "bar")))
wi_th(req, query = excluding(list(foo = "bar")))

## body
wi_th(req, body = list(foo = "bar"))
wi_th(req, body = including(list(foo = "bar")))
wi_th(req, body = excluding(list(foo = "bar")))

# cleanup
stub_registry_clear()

ropenscilabs/webmockr documentation built on Oct. 18, 2024, 8:58 p.m.