From 54f0355ea90473bf55cec0d59ef5fef6fa0b6bf9 Mon Sep 17 00:00:00 2001 From: Yorick Peterse Date: Tue, 8 Jul 2014 09:40:06 +0200 Subject: [PATCH] Basic specs for XPath::Evaluator. These currently only cover very simple XPath expressions. --- spec/oga/xpath/evaluator/paths_spec.rb | 65 ++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 spec/oga/xpath/evaluator/paths_spec.rb diff --git a/spec/oga/xpath/evaluator/paths_spec.rb b/spec/oga/xpath/evaluator/paths_spec.rb new file mode 100644 index 0000000..6873371 --- /dev/null +++ b/spec/oga/xpath/evaluator/paths_spec.rb @@ -0,0 +1,65 @@ +require 'spec_helper' + +describe Oga::XPath::Evaluator do + before do + @document = parse('') + @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