views:

230

answers:

2

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.

+1  A: 

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.

Paul Clapham
A: 

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
Daniel Cukier