+ 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')
+ for match_argument in self.arguments['match']:
+ matchNode.addChild(match_argument)
+
+ targetNode = libxml2.newNode('target-context')
+ for target_argument in self.arguments['target']:
+ targetNode.addChild(target_argument)
+
+ context[0].addChild(matchNode)
+ context[0].addChild(targetNode)
+ p.xpathFreeContext()
+
+ return doc
+