I’m using scalatest and want to say
actualXML should be === expectedXML
especially as === doesn’t care about attribute order. However the assertion fails when text has been embedded using Scala XML’s { … } syntax because
scala> <a>b {"c"}</a>.child
res8: scala.xml.Node* = ArrayBuffer(b , c)
whereas:
scala> <a>b c</a>.child
res9: scala.xml.Node* = ArrayBuffer(b c)
I can write a method
import scala.xml.Elem
import scala.xml.XML
def launder(xml: Elem): Elem = XML.loadString(xml.toString)
giving
launder(actualXML) should be === expectedXML
but would like to be able to use the vanilla syntax.
You can introduce your own Equalizer class specifically for Xml Elem:
So you’re introducing another implicit conversion but this time specifically for
Elem, which compares the laundered Elems.