diff --git a/spec/oga/xpath/evaluator/axes/ancestor_or_self_spec.rb b/spec/oga/xpath/evaluator/axes/ancestor_or_self_spec.rb
index 4f8f2b9..e31f65f 100644
--- a/spec/oga/xpath/evaluator/axes/ancestor_or_self_spec.rb
+++ b/spec/oga/xpath/evaluator/axes/ancestor_or_self_spec.rb
@@ -3,45 +3,27 @@ require 'spec_helper'
describe Oga::XPath::Evaluator do
context 'ancestor-or-self axis' do
before do
- @document = parse('')
- @c_node = @document.children[0].children[0].children[0]
- @evaluator = described_class.new(@c_node)
+ @document = parse('')
+
+ @a1 = @document.children[0]
+ @b1 = @a1.children[0]
+ @c1 = @b1.children[0]
end
- context 'direct ancestors' do
- before do
- @set = @evaluator.evaluate('ancestor-or-self::b')
- end
-
- it_behaves_like :node_set, :length => 1
-
- example 'return the ancestor' do
- @set[0].name.should == 'b'
- end
+ example 'return a node set containing the direct ancestor' do
+ evaluate_xpath(@c1, 'ancestor-or-self::b').should == node_set(@b1)
end
- context 'higher ancestors' do
- before do
- @set = @evaluator.evaluate('ancestor-or-self::a')
- end
-
- it_behaves_like :node_set, :length => 1
-
- example 'return the ancestor' do
- @set[0].name.should == 'a'
- end
+ example 'return a node set containing a higher ancestor' do
+ evaluate_xpath(@c1, 'ancestor-or-self::a').should == node_set(@a1)
end
- context 'ancestors that only match the context nodes' do
- before do
- @set = @evaluator.evaluate('ancestor-or-self::c')
- end
+ example 'return a node set containing the context node itself' do
+ evaluate_xpath(@c1, 'ancestor-or-self::c').should == node_set(@c1)
+ end
- it_behaves_like :node_set, :length => 1
-
- example 'return the node' do
- @set[0].name.should == 'c'
- end
+ example 'return an empty node set for non existing ancestors' do
+ evaluate_xpath(@c1, 'ancestor-or-self::foo').should == node_set
end
end
end
diff --git a/spec/oga/xpath/evaluator/axes/ancestor_spec.rb b/spec/oga/xpath/evaluator/axes/ancestor_spec.rb
index 13e831b..67ee4a5 100644
--- a/spec/oga/xpath/evaluator/axes/ancestor_spec.rb
+++ b/spec/oga/xpath/evaluator/axes/ancestor_spec.rb
@@ -3,41 +3,23 @@ require 'spec_helper'
describe Oga::XPath::Evaluator do
context 'ancestor axis' do
before do
- @document = parse('')
- @c_node = @document.children[0].children[0].children[0]
- @evaluator = described_class.new(@c_node)
+ @document = parse('')
+
+ @a1 = @document.children[0]
+ @b1 = @a1.children[0]
+ @c1 = @b1.children[0]
end
- context 'direct ancestors' do
- before do
- @set = @evaluator.evaluate('ancestor::b')
- end
-
- it_behaves_like :node_set, :length => 1
-
- example 'return the ancestor' do
- @set[0].name.should == 'b'
- end
+ example 'return a node set containing a direct ancestor' do
+ evaluate_xpath(@c1, 'ancestor::b').should == node_set(@b1)
end
- context 'higher ancestors' do
- before do
- @set = @evaluator.evaluate('ancestor::a')
- end
-
- it_behaves_like :node_set, :length => 1
-
- example 'return the ancestor' do
- @set[0].name.should == 'a'
- end
+ example 'return a node set containing a higher ancestor' do
+ evaluate_xpath(@c1, 'ancestor::a').should == node_set(@a1)
end
- context 'non existing ancestors' do
- before do
- @set = @evaluator.evaluate('ancestor::foobar')
- end
-
- it_behaves_like :empty_node_set
+ example 'return an empty node set for non existing ancestors' do
+ evaluate_xpath(@c1, 'ancestor::c').should == node_set
end
end
end
diff --git a/spec/oga/xpath/evaluator/axes/attribute_spec.rb b/spec/oga/xpath/evaluator/axes/attribute_spec.rb
index 5ca78d6..cc87b81 100644
--- a/spec/oga/xpath/evaluator/axes/attribute_spec.rb
+++ b/spec/oga/xpath/evaluator/axes/attribute_spec.rb
@@ -3,44 +3,22 @@ require 'spec_helper'
describe Oga::XPath::Evaluator do
context 'attribute axis' do
before do
- document = parse('')
- @evaluator = described_class.new(document.children[0])
+ @document = parse('')
+
+ @a1 = @document.children[0]
+ @attr = @a1.attribute('foo')
end
- context 'matching existing attributes' do
- before do
- @set = @evaluator.evaluate('attribute::foo')
- end
-
- it_behaves_like :node_set, :length => 1
-
- example 'return an Attribute instance' do
- @set[0].is_a?(Oga::XML::Attribute).should == true
- end
-
- example 'return the "foo" attribute' do
- @set[0].name.should == 'foo'
- end
+ example 'return a node set containing an attribute' do
+ evaluate_xpath(@a1, 'attribute::foo').should == node_set(@attr)
end
- context 'matching non existing attributes' do
- before do
- @set = @evaluator.evaluate('attribute::bar')
- end
-
- it_behaves_like :empty_node_set
+ example 'return a node set containing an attribute using the short form' do
+ evaluate_xpath(@a1, '@foo').should == node_set(@attr)
end
- context 'matching attributes using the short form' do
- before do
- @set = @evaluator.evaluate('@foo')
- end
-
- it_behaves_like :node_set, :length => 1
-
- example 'return the "foo" attribute' do
- @set[0].name.should == 'foo'
- end
+ example 'return an empty node set for non existing attributes' do
+ evaluate_xpath(@a1, 'attribute::bar').should == node_set
end
end
end
diff --git a/spec/oga/xpath/evaluator/axes/child_spec.rb b/spec/oga/xpath/evaluator/axes/child_spec.rb
index 25efae0..b80a8c4 100644
--- a/spec/oga/xpath/evaluator/axes/child_spec.rb
+++ b/spec/oga/xpath/evaluator/axes/child_spec.rb
@@ -3,40 +3,22 @@ require 'spec_helper'
describe Oga::XPath::Evaluator do
context 'child axis' do
before do
- @document = parse('')
- @evaluator = described_class.new(@document)
+ @document = parse('')
+
+ @a1 = @document.children[0]
+ @b1 = @a1.children[0]
end
- context 'direct children' do
- before do
- @set = @evaluator.evaluate('child::a')
- end
-
- it_behaves_like :node_set, :length => 1
-
- example 'return the node' do
- @set[0].name.should == 'a'
- end
+ example 'return a node set containing a direct child node' do
+ evaluate_xpath(@document, 'child::a').should == node_set(@a1)
end
- context 'nested children' do
- before do
- @set = @evaluator.evaluate('child::a/child::b')
- end
-
- it_behaves_like :node_set, :length => 1
-
- example 'return the node' do
- @set[0].name.should == 'b'
- end
+ example 'return a node set containing a nested child node' do
+ evaluate_xpath(@document, 'child::a/child::b').should == node_set(@b1)
end
- context 'non existing children' do
- before do
- @set = @evaluator.evaluate('child::b')
- end
-
- it_behaves_like :empty_node_set
+ example 'return an empty node set for non existing child nodes' do
+ evaluate_xpath(@document, 'child::x').should == node_set
end
end
end
diff --git a/spec/oga/xpath/evaluator/axes/descendant_or_self_spec.rb b/spec/oga/xpath/evaluator/axes/descendant_or_self_spec.rb
index 5b9f8ca..909fa06 100644
--- a/spec/oga/xpath/evaluator/axes/descendant_or_self_spec.rb
+++ b/spec/oga/xpath/evaluator/axes/descendant_or_self_spec.rb
@@ -3,199 +3,62 @@ require 'spec_helper'
describe Oga::XPath::Evaluator do
context 'descendant-or-self axis' do
before do
- document = parse('')
+ @document = parse('')
- @first_a = document.children[0]
- @first_b = @first_a.children[0]
- @second_b = @first_b.children[0]
- @first_c = @second_b.children[0]
- @evaluator = described_class.new(document)
+ @a1 = @document.children[0]
+ @b1 = @a1.children[0]
+ @b2 = @b1.children[0]
+ @c1 = @b2.children[0]
end
- context 'direct descendants' do
- before do
- @set = @evaluator.evaluate('descendant-or-self::b')
- end
-
- it_behaves_like :node_set, :length => 2
-
- example 'return the first node' do
- @set[0].should == @first_b
- end
-
- example 'return the second node' do
- @set[1].should == @second_b
- end
+ example 'return a node set containing a direct descendant' do
+ evaluate_xpath(@document, 'descendant-or-self::b')
+ .should == node_set(@b1, @b2)
end
- context 'nested descendants' do
- before do
- @set = @evaluator.evaluate('descendant-or-self::c')
- end
-
- it_behaves_like :node_set, :length => 1
-
- example 'return the node' do
- @set[0].should == @first_c
- end
+ example 'return a node set containing a nested descendant' do
+ evaluate_xpath(@document, 'descendant-or-self::c').should == node_set(@c1)
end
- context 'chained descendants' do
- before do
- @set = @evaluator.evaluate(
- 'descendant-or-self::a/descendant-or-self::*'
- )
- end
-
- it_behaves_like :node_set, :length => 4
-
- example 'return the node' do
- @set[0].should == @first_a
- end
-
- example 'return the first node' do
- @set[1].should == @first_b
- end
-
- example 'return the second node' do
- @set[2].should == @second_b
- end
-
- example 'return the node' do
- @set[3].should == @first_c
- end
+ example 'return a node set using multiple descendant expressions' do
+ evaluate_xpath(@document, 'descendant-or-self::a/descendant-or-self::*')
+ .should == node_set(@a1, @b1, @b2, @c1)
end
- context 'nested descendants with a matching predicate' do
- before do
- @set = @evaluator.evaluate('descendant-or-self::c[@class="x"]')
- end
-
- it_behaves_like :node_set, :length => 1
+ example 'return a node set containing a descendant with an attribute' do
+ evaluate_xpath(@document, 'descendant-or-self::c[@class="x"]')
+ .should == node_set(@c1)
end
- context 'descendants of a specific node' do
- before do
- @set = @evaluator.evaluate('a/descendant-or-self::b')
- end
-
- it_behaves_like :node_set, :length => 2
-
- example 'return the first node' do
- @set[0].should == @first_b
- end
-
- example 'return the second node' do
- @set[1].should == @second_b
- end
+ example 'return a node set containing a descendant relative to a node' do
+ evaluate_xpath(@document, 'a/descendant-or-self::b')
+ .should == node_set(@b1, @b2)
end
- context 'descendants matching self' do
- before do
- @set = @evaluator.evaluate('descendant-or-self::a')
- end
-
- it_behaves_like :node_set, :length => 1
-
- example 'return the first node' do
- @set[0].should == @first_a
- end
+ example 'return a node set containing the context node' do
+ evaluate_xpath(@document, 'descendant-or-self::a')
+ .should == node_set(@a1)
end
- context 'descendants of a specific node matching self' do
- before do
- @set = @evaluator.evaluate('a/b/b/c/descendant-or-self::c')
- end
-
- it_behaves_like :node_set, :length => 1
-
- example 'return the first node' do
- @set[0].should == @first_c
- end
+ example 'return a node set containing the context node relative to a node' do
+ evaluate_xpath(@document, 'a/b/b/c/descendant-or-self::c')
+ .should == node_set(@c1)
end
- context 'non existing descendants' do
- before do
- @set = @evaluator.evaluate('descendant-or-self::foobar')
- end
-
- it_behaves_like :empty_node_set
+ example 'return an empty node set for a non existing descendant' do
+ evaluate_xpath(@document, 'descendant-or-self::foobar').should == node_set
end
- context 'direct descendants without a matching predicate' do
- before do
- @set = @evaluator.evaluate('descendant-or-self::a[@class]')
- end
-
- it_behaves_like :empty_node_set
+ example 'return a node set containing a descendant using the short form' do
+ evaluate_xpath(@document, '//b').should == node_set(@b1, @b2)
end
- context 'nested descendants without a matching predicate' do
- before do
- @set = @evaluator.evaluate('descendant-or-self::b[@class]')
- end
-
- it_behaves_like :empty_node_set
+ example 'return a node set containing a nested descendant using the short form' do
+ evaluate_xpath(@document, '//a//*').should == node_set(@b1, @b2, @c1)
end
- context 'direct descendants using the short form' do
- before do
- @set = @evaluator.evaluate('//b')
- end
-
- it_behaves_like :node_set, :length => 2
-
- example 'return the first node' do
- @set[0].should == @first_b
- end
-
- example 'return the second node' do
- @set[1].should == @second_b
- end
- end
-
- context 'nested descendants using the short form' do
- before do
- @set = @evaluator.evaluate('//c')
- end
-
- it_behaves_like :node_set, :length => 1
-
- example 'return the node' do
- @set[0].should == @first_c
- end
- end
-
- context 'descendants of descendants usign the short form' do
- before do
- @set = @evaluator.evaluate('//a//*')
- end
-
- it_behaves_like :node_set, :length => 3
-
- example 'return the first node' do
- @set[0].should == @first_b
- end
-
- example 'return the second node' do
- @set[1].should == @second_b
- end
-
- example 'return the node' do
- @set[2].should == @first_c
- end
- end
-
- context 'children of descendants using the short form' do
- before do
- @set = @evaluator.evaluate('//a/b')
- end
-
- it_behaves_like :node_set, :length => 1
-
- example 'return the first node' do
- @set[0].should == @first_b
- end
+ example 'return a node set containing children of a descendant' do
+ evaluate_xpath(@document, '//a/b').should == node_set(@b1)
end
end
end
diff --git a/spec/oga/xpath/evaluator/axes/descendant_spec.rb b/spec/oga/xpath/evaluator/axes/descendant_spec.rb
index 85ac9ef..5de5330 100644
--- a/spec/oga/xpath/evaluator/axes/descendant_spec.rb
+++ b/spec/oga/xpath/evaluator/axes/descendant_spec.rb
@@ -3,60 +3,27 @@ require 'spec_helper'
describe Oga::XPath::Evaluator do
context 'descendant axis' do
before do
- @document = parse('')
- @evaluator = described_class.new(@document)
+ @document = parse('')
- @first_a = @document.children[0]
- @second_a = @first_a.children[-1]
+ @a1 = @document.children[0]
+ @a2 = @a1.children[-1]
+ @c1 = @a1.children[0].children[0]
end
- context 'direct descendants' do
- before do
- @set = @evaluator.evaluate('descendant::a')
- end
-
- it_behaves_like :node_set, :length => 2
-
- example 'return the first node' do
- @set[0].should == @first_a
- end
-
- example 'return the second node' do
- @set[1].should == @second_a
- end
+ example 'return a node set containing a direct descendant' do
+ evaluate_xpath(@document, 'descendant::a').should == node_set(@a1, @a2)
end
- context 'nested descendants' do
- before do
- @set = @evaluator.evaluate('descendant::c')
- end
-
- it_behaves_like :node_set, :length => 1
-
- example 'return the node' do
- @set[0].name.should == 'c'
- end
+ example 'return a node set containing a nested descendant' do
+ evaluate_xpath(@document, 'descendant::c').should == node_set(@c1)
end
- context 'descendants of a specific node' do
- before do
- @set = @evaluator.evaluate('a/descendant::a')
- end
-
- it_behaves_like :node_set, :length => 1
-
- example 'return the second node' do
- @set[0].should == @second_a
- end
+ example 'return a node set containing a descendant relative to a node' do
+ evaluate_xpath(@document, 'a/descendant::a').should == node_set(@a2)
end
- context 'non existing descendants' do
- before do
- # This should result in an empty set since has no children.
- @set = @evaluator.evaluate('a/b/c/descendant::c')
- end
-
- it_behaves_like :empty_node_set
+ example 'return an empty node set for non existing descendants' do
+ evaluate_xpath(@document, 'a/b/c/descendant::c').should == node_set
end
end
end
diff --git a/spec/oga/xpath/evaluator/axes/following_sibling_spec.rb b/spec/oga/xpath/evaluator/axes/following_sibling_spec.rb
index 2a731fa..ae5e6c2 100644
--- a/spec/oga/xpath/evaluator/axes/following_sibling_spec.rb
+++ b/spec/oga/xpath/evaluator/axes/following_sibling_spec.rb
@@ -16,44 +16,25 @@ describe Oga::XPath::Evaluator do
EOF
- @first_baz = @document.children[0].children[0].children[1]
- @second_baz = @first_baz.children[0]
- @third_baz = @document.children[0].children[1]
- @evaluator = described_class.new(@document)
+ @baz1 = @document.children[0].children[0].children[1]
+ @baz2 = @baz1.children[0]
+ @baz3 = @document.children[0].children[1]
end
# This should return an empty set since the document doesn't have any
# following nodes.
- context 'using a document as the root' do
- before do
- @set = @evaluator.evaluate('following-sibling::foo')
- end
-
- it_behaves_like :empty_node_set
+ example 'return an empty node set for the sibling of a document' do
+ evaluate_xpath(@document, 'following-sibling::foo').should == node_set
end
- context 'matching nodes in the current context' do
- before do
- @set = @evaluator.evaluate('root/foo/following-sibling::baz')
- end
-
- it_behaves_like :node_set, :length => 1
-
- example 'return the third node' do
- @set[0].should == @third_baz
- end
+ example 'return a node set containing the siblings of root/foo' do
+ evaluate_xpath(@document, 'root/foo/following-sibling::baz')
+ .should == node_set(@baz3)
end
- context 'matching nodes in a deeper context' do
- before do
- @set = @evaluator.evaluate('root/foo/bar/following-sibling::baz')
- end
-
- it_behaves_like :node_set, :length => 1
-
- example 'return the first node' do
- @set[0].should == @first_baz
- end
+ example 'return a node set containing the siblings of root/foo/bar' do
+ evaluate_xpath(@document, 'root/foo/bar/following-sibling::baz')
+ .should == node_set(@baz1)
end
end
end
diff --git a/spec/oga/xpath/evaluator/axes/following_spec.rb b/spec/oga/xpath/evaluator/axes/following_spec.rb
index d6d3411..27f5c00 100644
--- a/spec/oga/xpath/evaluator/axes/following_spec.rb
+++ b/spec/oga/xpath/evaluator/axes/following_spec.rb
@@ -16,52 +16,25 @@ describe Oga::XPath::Evaluator do
EOF
- @first_baz = @document.children[0].children[0].children[1]
- @second_baz = @first_baz.children[0]
- @third_baz = @document.children[0].children[1]
- @evaluator = described_class.new(@document)
+ @baz1 = @document.children[0].children[0].children[1]
+ @baz2 = @baz1.children[0]
+ @baz3 = @document.children[0].children[1]
end
# This should return an empty set since the document doesn't have any
# following nodes.
- context 'using a document as the root' do
- before do
- @set = @evaluator.evaluate('following::foo')
- end
-
- it_behaves_like :empty_node_set
+ example 'return an empty node set for the sibling of a document' do
+ evaluate_xpath(@document, 'following::foo').should == node_set
end
- context 'matching nodes in the current context' do
- before do
- @set = @evaluator.evaluate('root/foo/following::baz')
- end
-
- it_behaves_like :node_set, :length => 1
-
- example 'return the third node' do
- @set[0].should == @third_baz
- end
+ example 'return a node set containing the following nodes of root/foo' do
+ evaluate_xpath(@document, 'root/foo/following::baz')
+ .should == node_set(@baz3)
end
- context 'matching nodes in other contexts' do
- before do
- @set = @evaluator.evaluate('root/foo/bar/following::baz')
- end
-
- it_behaves_like :node_set, :length => 3
-
- example 'return the first node' do
- @set[0].should == @first_baz
- end
-
- example 'return the second node' do
- @set[1].should == @second_baz
- end
-
- example 'return the third node' do
- @set[2].should == @third_baz
- end
+ example 'return a node set containing the following nodes of root/foo/bar' do
+ evaluate_xpath(@document, 'root/foo/bar/following::baz')
+ .should == node_set(@baz1, @baz2, @baz3)
end
end
end
diff --git a/spec/oga/xpath/evaluator/axes/namespace_spec.rb b/spec/oga/xpath/evaluator/axes/namespace_spec.rb
index 72797fd..2b167b2 100644
--- a/spec/oga/xpath/evaluator/axes/namespace_spec.rb
+++ b/spec/oga/xpath/evaluator/axes/namespace_spec.rb
@@ -3,61 +3,27 @@ require 'spec_helper'
describe Oga::XPath::Evaluator do
context 'namespace axis' do
before do
- @document = parse(<<-EOF.strip)
-
-
-
- EOF
+ @document = parse('')
- @evaluator = described_class.new(@document)
+ @ns_x = @document.children[0].namespaces['x']
+ @ns_y = @document.children[0].children[0].namespaces['y']
end
- context 'matching namespaces in the entire document' do
- before do
- @set = @evaluator.evaluate('namespace::*')
- end
-
- it_behaves_like :empty_node_set
+ example 'return an empty node set for the document' do
+ evaluate_xpath(@document, 'namespace::*').should == node_set
end
- context 'matching namespaces in the root element' do
- before do
- @set = @evaluator.evaluate('root/namespace::x')
- end
-
- it_behaves_like :node_set, :length => 1
-
- example 'return a Namespace instance' do
- @set[0].is_a?(Oga::XML::Namespace).should == true
- end
-
- example 'return the "x" namespace' do
- @set[0].name.should == 'x'
- end
+ example 'return a node set containing the namespaces for root' do
+ evaluate_xpath(@document, 'root/namespace::x').should == node_set(@ns_x)
end
- context 'matching namespaces in a nested element' do
- before do
- @set = @evaluator.evaluate('root/foo/namespace::*')
- end
-
- it_behaves_like :node_set, :length => 2
-
- example 'return the "y" namespace' do
- @set[0].name.should == 'y'
- end
-
- example 'return the "x" namespace' do
- @set[1].name.should == 'x'
- end
+ example 'return a node set containing the namespaces for root/foo' do
+ evaluate_xpath(@document, 'root/foo/namespace::*')
+ .should == node_set(@ns_y, @ns_x)
end
- context 'matching namespace nodes using a wildcard' do
- before do
- @set = @evaluator.evaluate('root/namespace::*')
- end
-
- it_behaves_like :node_set, :length => 1
+ example 'return a node set containing the namespaces for root using a wildcard' do
+ evaluate_xpath(@document, 'root/namespace::*').should == node_set(@ns_x)
end
end
end
diff --git a/spec/oga/xpath/evaluator/axes/parent_spec.rb b/spec/oga/xpath/evaluator/axes/parent_spec.rb
index 801be4f..837a9d0 100644
--- a/spec/oga/xpath/evaluator/axes/parent_spec.rb
+++ b/spec/oga/xpath/evaluator/axes/parent_spec.rb
@@ -3,40 +3,21 @@ require 'spec_helper'
describe Oga::XPath::Evaluator do
context 'parent axis' do
before do
- @document = parse('')
- @evaluator = described_class.new(@document)
+ @document = parse('')
+
+ @a1 = @document.children[0]
end
- context 'matching nodes without parents' do
- before do
- @set = @evaluator.evaluate('parent::a')
- end
-
- it_behaves_like :empty_node_set
+ example 'return an empty node set for non existing parents' do
+ evaluate_xpath(@document, 'parent::a').should == node_set
end
- context 'matching nodes with parents' do
- before do
- @set = @evaluator.evaluate('a/b/parent::a')
- end
-
- it_behaves_like :node_set, :length => 1
-
- example 'return the node' do
- @set[0].should == @document.children[0]
- end
+ example 'return a node set containing parents of a node' do
+ evaluate_xpath(@document, 'a/b/parent::a').should == node_set(@a1)
end
- context 'matching nodes with parents using the short form' do
- before do
- @set = @evaluator.evaluate('a/b/..')
- end
-
- it_behaves_like :node_set, :length => 1
-
- example 'return the node' do
- @set[0].should == @document.children[0]
- end
+ example 'return a node set containing parents of a node using the short form' do
+ evaluate_xpath(@document, 'a/b/..').should == node_set(@a1)
end
end
end
diff --git a/spec/oga/xpath/evaluator/axes/preceding_sibling_spec.rb b/spec/oga/xpath/evaluator/axes/preceding_sibling_spec.rb
index 27b015e..8cb0e4c 100644
--- a/spec/oga/xpath/evaluator/axes/preceding_sibling_spec.rb
+++ b/spec/oga/xpath/evaluator/axes/preceding_sibling_spec.rb
@@ -14,20 +14,18 @@ describe Oga::XPath::Evaluator do
EOF
- @second_foo = @document.children[0].children[1].children[0]
- @evaluator = described_class.new(@document)
+ @foo1 = @document.children[0].children[0]
+ @foo2 = @document.children[0].children[1].children[0]
end
- context 'matching nodes in the current context' do
- before do
- @set = @evaluator.evaluate('root/bar/baz/preceding-sibling::foo')
- end
+ example 'return a node set containing preceding siblings of root/bar' do
+ evaluate_xpath(@document, 'root/bar/preceding-sibling::foo')
+ .should == node_set(@foo1)
+ end
- it_behaves_like :node_set, :length => 1
-
- example 'return the second node' do
- @set[0].should == @second_foo
- end
+ example 'return a node set containing preceding siblings of root/bar/baz' do
+ evaluate_xpath(@document, 'root/bar/baz/preceding-sibling::foo')
+ .should == node_set(@foo2)
end
end
end
diff --git a/spec/oga/xpath/evaluator/axes/preceding_spec.rb b/spec/oga/xpath/evaluator/axes/preceding_spec.rb
index a87d9f4..b302590 100644
--- a/spec/oga/xpath/evaluator/axes/preceding_spec.rb
+++ b/spec/oga/xpath/evaluator/axes/preceding_spec.rb
@@ -15,39 +15,20 @@ describe Oga::XPath::Evaluator do
EOF
- @first_foo = @document.children[0].children[0]
- @first_bar = @first_foo.children[0]
- @first_baz = @first_foo.children[1]
- @second_baz = @first_baz.children[0]
- @evaluator = described_class.new(@document)
+ @foo1 = @document.children[0].children[0]
+ @bar1 = @foo1.children[0]
+ @baz1 = @foo1.children[1]
+ @baz2 = @baz1.children[0]
end
- context 'matching nodes in the current context' do
- before do
- @set = @evaluator.evaluate('root/foo/baz/preceding::bar')
- end
-
- it_behaves_like :node_set, :length => 1
-
- example 'return the first node' do
- @set[0].should == @first_bar
- end
+ example 'return a node set containing preceding nodes of root/foo/baz' do
+ evaluate_xpath(@document, 'root/foo/baz/preceding::bar')
+ .should == node_set(@bar1)
end
- context 'matching nodes in other contexts' do
- before do
- @set = @evaluator.evaluate('root/baz/preceding::baz')
- end
-
- it_behaves_like :node_set, :length => 2
-
- example 'return the first node' do
- @set[0].should == @first_baz
- end
-
- example 'return the second node' do
- @set[1].should == @second_baz
- end
+ example 'return a node set containing preceding nodes for root/baz' do
+ evaluate_xpath(@document, 'root/baz/preceding::baz')
+ .should == node_set(@baz1, @baz2)
end
end
end
diff --git a/spec/oga/xpath/evaluator/axes/self_spec.rb b/spec/oga/xpath/evaluator/axes/self_spec.rb
index 85eb0e8..3d8275d 100644
--- a/spec/oga/xpath/evaluator/axes/self_spec.rb
+++ b/spec/oga/xpath/evaluator/axes/self_spec.rb
@@ -3,88 +3,39 @@ require 'spec_helper'
describe Oga::XPath::Evaluator do
context 'self axis' do
before do
- @document = parse('foobartest')
- @evaluator = described_class.new(@document)
+ @document = parse('foobartest')
+
+ @a1 = @document.children[0]
+ @b1 = @a1.children[0]
+ @b2 = @a1.children[1]
end
- context 'matching the context node itself' do
- before do
- @set = @evaluator.evaluate('a/self::a')
- end
-
- it_behaves_like :node_set, :length => 1
-
- example 'return the node' do
- @set[0].should == @document.children[0]
- end
+ example 'return a node set containing the context node' do
+ evaluate_xpath(@document, 'a/self::a').should == node_set(@a1)
end
- context 'matching non existing nodes' do
- before do
- @set = @evaluator.evaluate('a/self::b')
- end
-
- it_behaves_like :empty_node_set
+ example 'return an empty node set for non existing nodes' do
+ evaluate_xpath(@document, 'a/self::b').should == node_set
end
- context 'matching the context node itself using the short form' do
- before do
- @set = @evaluator.evaluate('a/.')
- end
-
- it_behaves_like :node_set, :length => 1
-
- example 'return the node' do
- @set[0].should == @document.children[0]
- end
+ example 'return a node set containing the context node using the short form' do
+ evaluate_xpath(@document, 'a/.').should == node_set(@a1)
end
- context 'matching nodes inside predicates' do
- before do
- @set = @evaluator.evaluate('a/b[. = "foo"]')
- end
-
- it_behaves_like :node_set, :length => 1
-
- example 'return the first node' do
- @set[0].should == @document.children[0].children[0]
- end
+ example 'return a node set by matching the text of a node' do
+ evaluate_xpath(@document, 'a/b[. = "foo"]').should == node_set(@b1)
end
- context 'using self inside a path inside a predicate' do
- before do
- @set = @evaluator.evaluate('a/b[c/. = "test"]')
- end
-
- it_behaves_like :node_set, :length => 1
-
- example 'return the second node' do
- @set[0].should == @document.children[0].children[1]
- end
+ example 'return a node set by matching the text of a path' do
+ evaluate_xpath(@document, 'a/b[c/. = "test"]').should == node_set(@b2)
end
- context 'using self inside a nested predicate' do
- before do
- @set = @evaluator.evaluate('a/b[c[. = "test"]]')
- end
-
- it_behaves_like :node_set, :length => 1
-
- example 'return the second node' do
- @set[0].should == @document.children[0].children[1]
- end
+ example 'return a node set by matching the text of a nested predicate' do
+ evaluate_xpath(@document, 'a/b[c[. = "test"]]').should == node_set(@b2)
end
- context 'matching the document itself' do
- before do
- @set = @evaluator.evaluate('self::node()')
- end
-
- it_behaves_like :node_set, :length => 1
-
- example 'return the document itself' do
- @set[0].is_a?(Oga::XML::Document).should == true
- end
+ example 'return a node set containing the document itself' do
+ evaluate_xpath(@document, 'self::node()').should == node_set(@document)
end
end
end