Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Order of xml body matters #82

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

Order of xml body matters #82

nickhammond opened this issue Apr 7, 2011 · 3 comments

Comments

@nickhammond
Copy link

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
Copy link
Author

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
Copy link
Author

mention failure

@nickhammond
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant