diff --git a/spec/oga/xpath/compiler/html_spec.rb b/spec/oga/xpath/compiler/html_spec.rb
index de0cc14..a29c340 100644
--- a/spec/oga/xpath/compiler/html_spec.rb
+++ b/spec/oga/xpath/compiler/html_spec.rb
@@ -1,14 +1,16 @@
require 'spec_helper'
describe Oga::XPath::Compiler do
- describe 'querying HTML documents' do
- before do
- @document = parse_html('
')
- @body = @document.children[0].children[0]
- end
+ before do
+ @document = parse_html('')
+ @body = @document.children[0].children[0]
+ end
- it 'returns a NodeSet when a custom default namespace is declared' do
- evaluate_xpath(@document, 'html/body').should == node_set(@body)
+ describe 'relative to an HTML document' do
+ describe 'html/body' do
+ it 'returns a NodeSet' do
+ evaluate_xpath(@document).should == node_set(@body)
+ end
end
end
end
diff --git a/spec/oga/xpath/compiler/predicates_spec.rb b/spec/oga/xpath/compiler/predicates_spec.rb
index b5ca410..40a4be8 100644
--- a/spec/oga/xpath/compiler/predicates_spec.rb
+++ b/spec/oga/xpath/compiler/predicates_spec.rb
@@ -1,31 +1,31 @@
require 'spec_helper'
describe Oga::XPath::Compiler do
- describe 'predicates' do
- before do
- @document = parse('1020')
+ before do
+ @document = parse('1020')
- root = @document.children[0]
+ root = @document.children[0]
- @a1 = root.children[0]
- @a2 = root.children[1]
- end
+ @a1 = root.children[0]
+ @a2 = root.children[1]
+ end
- describe 'using an integer as an index' do
- it 'returns a NodeSet containing the first node' do
- evaluate_xpath(@document, 'root/a[1]').should == node_set(@a1)
+ describe 'relative to a document' do
+ describe 'root/a[1]' do
+ it 'returns a NodeSet' do
+ evaluate_xpath(@document).should == node_set(@a1)
end
end
- describe 'using a float as an index' do
- it 'returns a NodeSet containing the first node' do
- evaluate_xpath(@document, 'root/a[1.5]').should == node_set(@a1)
+ describe 'root/a[1.5]' do
+ it 'returns a NodeSet' do
+ evaluate_xpath(@document).should == node_set(@a1)
end
end
- describe 'using a node test' do
- it 'returns a NodeSet containing all nodes with child nodes' do
- evaluate_xpath(@document, 'root/a[b]').should == node_set(@a2)
+ describe 'root/a[b]' do
+ it 'returns a NodeSet' do
+ evaluate_xpath(@document).should == node_set(@a2)
end
end
end
diff --git a/spec/oga/xpath/compiler/variables_spec.rb b/spec/oga/xpath/compiler/variables_spec.rb
index e3bafbe..753843d 100644
--- a/spec/oga/xpath/compiler/variables_spec.rb
+++ b/spec/oga/xpath/compiler/variables_spec.rb
@@ -7,19 +7,23 @@ describe Oga::XPath::Compiler do
@compiler = described_class.new
end
- it 'returns the value of a variable' do
- ast = parse_xpath('$number')
- block = @compiler.compile(ast)
+ describe 'when a variable is defined' do
+ it 'returns the value of a variable' do
+ ast = parse_xpath('$number')
+ block = @compiler.compile(ast)
- block.call(@document, 'number' => 10.0).should == 10.0
+ block.call(@document, 'number' => 10.0).should == 10.0
+ end
end
- it 'raises RuntimeError when evaluating an unbound variable' do
- ast = parse_xpath('$number')
- block = @compiler.compile(ast)
+ describe 'when a variable is undefined' do
+ it 'raises RuntimeError' do
+ ast = parse_xpath('$number')
+ block = @compiler.compile(ast)
- proc { block.call(@document) }.should
- raise_error 'Undefined XPath variable: number'
+ proc { block.call(@document) }.should
+ raise_error 'Undefined XPath variable: number'
+ end
end
end
end
diff --git a/spec/oga/xpath/compiler/wildcard_spec.rb b/spec/oga/xpath/compiler/wildcard_spec.rb
index bbb9b03..19ea2f6 100644
--- a/spec/oga/xpath/compiler/wildcard_spec.rb
+++ b/spec/oga/xpath/compiler/wildcard_spec.rb
@@ -1,30 +1,38 @@
require 'spec_helper'
describe Oga::XPath::Compiler do
- describe 'wildcard paths' do
- before do
- @document = parse('')
+ before do
+ @document = parse('')
- @a1 = @document.children[0]
- @b1 = @a1.children[0]
- @b2 = @a1.children[1]
- @c1 = @a1.children[2]
+ @a1 = @document.children[0]
+ @b1 = @a1.children[0]
+ @b2 = @a1.children[1]
+ @c1 = @a1.children[2]
+ end
+
+ describe 'relative to a document' do
+ describe 'a/*' do
+ it 'returns a NodeSet' do
+ evaluate_xpath(@document).should == @a1.children
+ end
end
- it 'evaluates a wildcard path' do
- evaluate_xpath(@document, 'a/*').should == @a1.children
+ describe 'a/*:b' do
+ it 'returns a NodeSet' do
+ evaluate_xpath(@document).should == node_set(@b1, @b2)
+ end
end
- it 'evaluates a path using a namespace wildcard' do
- evaluate_xpath(@document, 'a/*:b').should == node_set(@b1, @b2)
+ describe 'a/ns1:*' do
+ it 'returns a NodeSet' do
+ evaluate_xpath(@document).should == node_set(@c1)
+ end
end
- it 'evaluates a path using a namespace and a name wildcard' do
- evaluate_xpath(@document, 'a/ns1:*').should == node_set(@c1)
- end
-
- it 'evaluates a containing a namespace wildcard and a name wildcard' do
- evaluate_xpath(@document, 'a/*:*').should == @a1.children
+ describe 'a/*:*' do
+ it 'returns a NodeSet' do
+ evaluate_xpath(@document).should == @a1.children
+ end
end
end
end