Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Order of xml body matters #82

Closed
nickhammond opened this Issue · 3 comments

1 participant

@nickhammond

Shouldn't this work if the content_type is specified as xml? Technically if you parse that xml it would be equal.

it "should match the body pattern regardless of order for xml requests" do
  @request_pattern.with(:body => 
  "<?xml version=\"1.0\" encoding=\"UTF-8\"?><subscription><first>f</first><last>l</last></subscription", :content_type => "application/xml")
  @request_pattern.to_s.should ==WebMock::RequestPattern.new(:get, "www.example.com", :body => 
  "<?xml version=\"1.0\" encoding=\"UTF-8\"?><subscription><last>l</last><first>f</first></subscription", :content_type => "application/xml").to_s
end

1) WebMock::RequestPattern with should match the body pattern regardless of order for xml requests
 Failure/Error: "<?xml version=\"1.0\" encoding=\"UTF-8\"?><subscription><last>l</last><first>f</first></subscription", :content_type => "application/xml").to_s
   expected: "GET http://www.example.com/ with body \"<?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?><subscription><last>l</last><first>f</first></subscription\""
        got: "GET http://www.example.com/ with body \"<?xml version=\\\"1.0\\\" encoding=\\\"UTF-8\\\"?><subscription><first>f</first><last>l</last></subscription\"" (using ==)
 # ./spec/request_pattern_spec.rb:36
@nickhammond

This example is closer to the example in the readme.

it "should match the body pattern regardless of order for xml requests" do
  @request_pattern.with(:body => {:subscription => {:first => "f", :last => "l"}})
  @request_pattern.to_s.should ==WebMock::RequestPattern.new(:get, "www.example.com", :body => 
  "<?xml version=\"1.0\" encoding=\"UTF-8\"?><subscription><last>l</last><first>f</first></subscription", :headers => {"Content-Type" => 'application/xml'}).to_s
end
@nickhammond

mention failure

@nickhammond

I found another passing tests that validated that this works fine.

Basically the best practice is to have the request body as a hash and have the response body converted to the content type.

@nickhammond nickhammond closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.