+ def add_rule_context_to_rspec(self, doc):
+ p = doc.xpathNewContext()
+ context = p.xpathEval("//rspec")
+ if (not context):
+ raise Exception('Request is not an rspec')
+ else:
+ # Add the request context
+ matchNode = libxml2.newNode('match-context')
+ matchNode.addChild(self.arguments['match'])
+ targetNode = libxml2.newNode('target-context')
+ targetNode.addChild(self.arguments['target'])
+ context[0].addChild(matchNode)
+ context[0].addChild(targetNode)
+ p.xpathFreeContext()
+
+ return doc
+