Skip to content

Instantly share code, notes, and snippets.

@vdichev
Created August 11, 2010 03:40
Show Gist options
  • Save vdichev/518434 to your computer and use it in GitHub Desktop.
Save vdichev/518434 to your computer and use it in GitHub Desktop.
trait XmlResponse {
self: TestResponse =>
def xmlMatch(f: Elem => Unit)
(implicit errorFunc: ReportFailure): TestResponse = {
if (this.asInstanceOf[SelfType].code != 200)
errorFunc.fail("Response status is not 200!")
xml match {
case Full(xml) => f(xml); this
case _ => errorFunc.fail("Response contains no XML!")
}
}
def \\(node: Node): TestResponse =
xmlMatch(_ must XmlBaseMatchers.\\(node))
def !\\(node: Node): TestResponse =
xmlMatch(_ must not(XmlBaseMatchers.\\(node)))
def \(node: Node): TestResponse =
xmlMatch(_ must XmlBaseMatchers.\(node))
def !\(node: Node): TestResponse =
xmlMatch(_ must not(XmlBaseMatchers.\(node)))
def \\(label: String): TestResponse =
xmlMatch(_ must XmlBaseMatchers.\\(label))
def !\\(label: String): TestResponse =
xmlMatch(_ must not(XmlBaseMatchers.\\(label)))
def \(label: String): TestResponse =
xmlMatch(_ must XmlBaseMatchers.\(label))
def !\(label: String): TestResponse =
xmlMatch(_ must not(XmlBaseMatchers.\(label)))
}
implicit def testResponse2XmlResponse(response: TestResponse): XmlResponse = {
val r = response.asInstanceOf[response.SelfType]
new response.SelfType(r.baseUrl,
r.code,
r.msg,
r.headers,
r.body,
r.theHttpClient) with XmlResponse
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment