Skip to content

Make it possible to flexibly compare XML bodies #134

@sckott

Description

@sckott

Right now a user has to give an xml class item to stub_request to match to an xml request body because for request bodies if we detect xml we just use xml2::read_xml which gives a xml_document class, which appears we can not compare to even another xml_doc probably because they have different pointers

x = read_xml("<foo> <bar> text <baz/> </bar> </foo>")
y = read_xml("<foo> <bar> text <baz/> </bar> </foo>")
identical(x, y)
#> [1] FALSE

What we're aiming for is to be able to do the following

stub_request(:post, "www.example.com").
  with(body: {data: {a: '1', b: 'five'}})

RestClient.post('www.example.com', "data[a]=1&data[b]=five",
  content_type: 'application/x-www-form-urlencoded')    # ===> Success

RestClient.post('www.example.com', '{"data":{"a":"1","b":"five"}}',
  content_type: 'application/json')    # ===> Success

RestClient.post('www.example.com', '<data a="1" b="five" />',
  content_type: 'application/xml')    # ===> Success

In which the stub can just have an R list while the request body has XML (or JSON or a list itself), but we can still compare them

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions