开发者

XML testing in Rails - Fixed attributes order in Builder::XmlMarkup in ruby -

I have the following test in my Rails Application:

it "should validate xml" do
  builder 开发者_如何转开发= Builder::XmlMarkup.new
  builder.server(:name => "myServer", :ip => "192.168.1.1").should == "<server name=\"myServer\" ip=\"192.168.1.1\"/>"
end

The problem is that this test passes sometimes, because the order of the xml tag attributes is unpredictable. Is there a way to force this order? Is there any other easy way to build xml?

This example is simplified, I have a big XML. My problem is that I want to do an integration test, which compares a WebService call with a fixed XML file. Otherwise, I would have to parse the xml and verify element by element in the XML.


The order of attributes in an element is unpredictable according to the XML Recommendation. So if you have a test which expects attributes to be in a particular order, that test is incorrect.


At the end, I've used the .should have_tag assertion:

it "should validate xml" do
  builder = Builder::XmlMarkup.new
  xml = builder.server(:name => "myServer", :ip => "192.168.1.1")
  xml.should have_tag("server[name=myServer]")
  xml.should have_tag("server[ip=192.168.1.1]")
end
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜