From d0177633f886e09189a85f3f8ee5d6255c1c7414 Mon Sep 17 00:00:00 2001 From: Yorick Peterse Date: Fri, 28 Aug 2015 15:58:42 +0200 Subject: [PATCH] Revamp namespace compiler specs --- .../oga/xpath/compiler/axes/namespace_spec.rb | 55 ++++++++++++++----- 1 file changed, 41 insertions(+), 14 deletions(-) diff --git a/spec/oga/xpath/compiler/axes/namespace_spec.rb b/spec/oga/xpath/compiler/axes/namespace_spec.rb index 2adce10..d2e5cfb 100644 --- a/spec/oga/xpath/compiler/axes/namespace_spec.rb +++ b/spec/oga/xpath/compiler/axes/namespace_spec.rb @@ -1,29 +1,56 @@ require 'spec_helper' describe Oga::XPath::Compiler do - describe 'namespace axis' do - before do - @document = parse('') + before do + @document = parse('') - @ns_x = @document.children[0].namespaces['x'] - @ns_y = @document.children[0].children[0].namespaces['y'] + @ns_x = @document.children[0].namespaces['x'] + @ns_y = @document.children[0].children[0].namespaces['y'] + end + + describe 'relative to a document' do + describe 'namespace::*' do + it 'returns an empty NodeSet' do + evaluate_xpath(@document).should == node_set + end end - it 'returns an empty node set for the document' do - evaluate_xpath(@document, 'namespace::*').should == node_set + describe 'root/namespace::x' do + it 'returns a NodeSet' do + evaluate_xpath(@document).should == node_set(@ns_x) + end end - it 'returns a node set containing the namespaces for root' do - evaluate_xpath(@document, 'root/namespace::x').should == node_set(@ns_x) + describe 'root/foo/namespace::*' do + it 'returns a NodeSet' do + evaluate_xpath(@document).should == node_set(@ns_y, @ns_x) + end end - it 'returns a node set containing the namespaces for root/foo' do - evaluate_xpath(@document, 'root/foo/namespace::*') - .should == node_set(@ns_y, @ns_x) + describe 'root/namespace::*' do + it 'returns a NodeSet' do + evaluate_xpath(@document).should == node_set(@ns_x) + end end + end - it 'returns a node set containing the namespaces for root using a wildcard' do - evaluate_xpath(@document, 'root/namespace::*').should == node_set(@ns_x) + describe 'relative to an element' do + describe 'namespace::x' do + it 'returns a NodeSet' do + root = @document.children[0] + + evaluate_xpath(root).should == node_set(@ns_x) + end + end + end + + describe 'relative to an attribute' do + describe 'namespace::x' do + it 'returns an empty NodeSet' do + root = @document.children[0] + + evaluate_xpath(root.attribute('foo')).should == node_set + end end end end