Order of xml body matters #82

Closed
nickhammond opened this Issue Apr 7, 2011 · 3 comments

Comments

Projects
None yet
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 comment has been minimized.

Show comment Hide comment
@nickhammond

nickhammond Apr 7, 2011

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

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

This comment has been minimized.

Show comment Hide comment
@nickhammond

nickhammond Apr 7, 2011

mention failure

mention failure

@nickhammond

This comment has been minimized.

Show comment Hide comment
@nickhammond

nickhammond Apr 8, 2011

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.

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 Apr 8, 2011

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment