Basic specs for XPath::Evaluator.

These currently only cover very simple XPath expressions.
This commit is contained in:
Yorick Peterse 2014-07-08 09:40:06 +02:00
parent 808e1e8c47
commit 54f0355ea9
1 changed files with 65 additions and 0 deletions

View File

@ -0,0 +1,65 @@
require 'spec_helper'
describe Oga::XPath::Evaluator do
before do
@document = parse('<a><b></b><b></b></a>')
@evaluator = described_class.new(@document)
end
context 'absolute paths' do
before do
@set = @evaluator.evaluate('/a')
end
example 'return a NodeSet instance' do
@set.is_a?(Oga::XML::NodeSet).should == true
end
example 'return the right amount of nodes' do
@set.length.should == 1
end
example 'return the correct nodes' do
@set[0].should == @document.children[0]
end
end
context 'relative paths' do
before do
@set = @evaluator.evaluate('a')
end
example 'return a NodeSet instance' do
@set.is_a?(Oga::XML::NodeSet).should == true
end
example 'return the right amount of nodes' do
@set.length.should == 1
end
example 'return the correct nodes' do
@set[0].should == @document.children[0]
end
end
context 'nested paths' do
before do
@set = @evaluator.evaluate('/a/b')
end
example 'return a NodeSet instance' do
@set.is_a?(Oga::XML::NodeSet).should == true
end
example 'return the right amount of rows' do
@set.length.should == 2
end
example 'return the correct nodes' do
a = @document.children[0]
@set[0].should == a.children[0]
@set[1].should == a.children[1]
end
end
end