Rewrote XPath evaluator predicates spec.

This commit is contained in:
Yorick Peterse 2014-11-09 18:52:04 +01:00
parent 3893e56ca8
commit ceed3a6046
1 changed files with 9 additions and 11 deletions

View File

@ -3,20 +3,18 @@ require 'spec_helper'
describe Oga::XPath::Evaluator do
context 'predicates' do
before do
@document = parse('<root><a></a><b>10</b><b>20</b></root>')
@evaluator = described_class.new(@document)
@document = parse('<root><b>10</b><b>20</b></root>')
@b1 = @document.children[0].children[0]
@b2 = @document.children[0].children[1]
end
context 'using predicate indexes' do
before do
@set = @evaluator.evaluate('root/b[2]')
end
example 'evaluate a predicate that returns the first <b> node' do
evaluate_xpath(@document, 'root/b[1]').should == node_set(@b1)
end
it_behaves_like :node_set, :length => 1
example 'return the second <b> node' do
@set[0].should == @document.children[0].children[-1]
end
example 'evaluate a predicate that returns the second <b> node' do
evaluate_xpath(@document, 'root/b[2]').should == node_set(@b2)
end
end
end