diff --git a/spec/oga/xpath/evaluator/type_tests/comment_spec.rb b/spec/oga/xpath/evaluator/type_tests/comment_spec.rb index 8cd72ed..37b0add 100644 --- a/spec/oga/xpath/evaluator/type_tests/comment_spec.rb +++ b/spec/oga/xpath/evaluator/type_tests/comment_spec.rb @@ -3,40 +3,18 @@ require 'spec_helper' describe Oga::XPath::Evaluator do context 'comment() tests' do before do - @document = parse('') - @evaluator = described_class.new(@document) + @document = parse('') + + @comment1 = @document.children[0].children[0] + @comment2 = @document.children[0].children[1].children[0] end - context 'matching comment nodes' do - before do - @set = @evaluator.evaluate('a/comment()') - end - - it_behaves_like :node_set, :length => 1 - - example 'return a Comment instance' do - @set[0].is_a?(Oga::XML::Comment).should == true - end - - example 'return the "foo" comment node' do - @set[0].text.should == 'foo' - end + example 'return a node set containing comment nodes' do + evaluate_xpath(@document, 'a/comment()').should == node_set(@comment1) end - context 'matching nested comment nodes' do - before do - @set = @evaluator.evaluate('a/b/comment()') - end - - it_behaves_like :node_set, :length => 1 - - example 'return a Comment instance' do - @set[0].is_a?(Oga::XML::Comment).should == true - end - - example 'return the "bar" comment node' do - @set[0].text.should == 'bar' - end + example 'return a node set containing nested comments' do + evaluate_xpath(@document, 'a/b/comment()').should == node_set(@comment2) end end end diff --git a/spec/oga/xpath/evaluator/type_tests/node_spec.rb b/spec/oga/xpath/evaluator/type_tests/node_spec.rb index e721e31..f7f5a6f 100644 --- a/spec/oga/xpath/evaluator/type_tests/node_spec.rb +++ b/spec/oga/xpath/evaluator/type_tests/node_spec.rb @@ -3,56 +3,25 @@ require 'spec_helper' describe Oga::XPath::Evaluator do context 'node() tests' do before do - @document = parse('foo') - @evaluator = described_class.new(@document) + @document = parse('foo') + + @a1 = @document.children[0] + @b1 = @a1.children[0] + @comment1 = @a1.children[1] + @cdata1 = @a1.children[2] end - context 'matching elements' do - before do - @set = @evaluator.evaluate('node()') - 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 elements' do + evaluate_xpath(@document, 'node()').should == node_set(@a1) end - context 'matching nested elements' do - before do - @set = @evaluator.evaluate('a/node()') - end - - it_behaves_like :node_set, :length => 3 - - example 'return the node' do - @set[0].name.should == 'b' - end - - example 'return the "foo" comment' do - @set[1].text.should == 'foo' - end - - example 'return the "bar" CDATA tag' do - @set[2].text.should == 'bar' - end + example 'return a node set containing elements, comments and CDATA tags' do + evaluate_xpath(@document, 'a/node()') + .should == node_set(@b1, @comment1, @cdata1) end - context 'matching text nodes' do - before do - @set = @evaluator.evaluate('a/b/node()') - end - - it_behaves_like :node_set, :length => 1 - - example 'return a Text instance' do - @set[0].is_a?(Oga::XML::Text).should == true - end - - example 'include the text' do - @set[0].text.should == 'foo' - end + example 'return a node set containing text nodes' do + evaluate_xpath(@document, 'a/b/node()').should == node_set(@b1.children[0]) end end end diff --git a/spec/oga/xpath/evaluator/type_tests/processing_instruction_spec.rb b/spec/oga/xpath/evaluator/type_tests/processing_instruction_spec.rb index f3e92b5..18d9a79 100644 --- a/spec/oga/xpath/evaluator/type_tests/processing_instruction_spec.rb +++ b/spec/oga/xpath/evaluator/type_tests/processing_instruction_spec.rb @@ -3,40 +3,20 @@ require 'spec_helper' describe Oga::XPath::Evaluator do context 'processing-instruction() tests' do before do - @document = parse('') - @evaluator = described_class.new(@document) + @document = parse('') + + @proc_ins1 = @document.children[0].children[0] + @proc_ins2 = @document.children[0].children[1].children[0] end - context 'matching processing instruction nodes' do - before do - @set = @evaluator.evaluate('a/processing-instruction()') - end - - it_behaves_like :node_set, :length => 1 - - example 'return a ProcessingInstruction instance' do - @set[0].is_a?(Oga::XML::ProcessingInstruction).should == true - end - - example 'return the "foo" node' do - @set[0].text.should == ' foo ' - end + example 'return a node set containing processing instructions' do + evaluate_xpath(@document, 'a/processing-instruction()') + .should == node_set(@proc_ins1) end - context 'matching nested processing instruction nodes' do - before do - @set = @evaluator.evaluate('a/b/processing-instruction()') - end - - it_behaves_like :node_set, :length => 1 - - example 'return a ProcessingInstruction instance' do - @set[0].is_a?(Oga::XML::ProcessingInstruction).should == true - end - - example 'return the "bar" node' do - @set[0].text.should == ' bar ' - end + example 'return a node set containing nested processing instructions' do + evaluate_xpath(@document, 'a/b/processing-instruction()') + .should == node_set(@proc_ins2) end end end diff --git a/spec/oga/xpath/evaluator/type_tests/text_spec.rb b/spec/oga/xpath/evaluator/type_tests/text_spec.rb index 40825f7..f657855 100644 --- a/spec/oga/xpath/evaluator/type_tests/text_spec.rb +++ b/spec/oga/xpath/evaluator/type_tests/text_spec.rb @@ -3,40 +3,18 @@ require 'spec_helper' describe Oga::XPath::Evaluator do context 'text() tests' do before do - @document = parse('foobar') - @evaluator = described_class.new(@document) + @document = parse('foobar') + + @text1 = @document.children[0].children[0] + @text2 = @document.children[0].children[1].children[0] end - context 'matching text nodes' do - before do - @set = @evaluator.evaluate('a/text()') - end - - it_behaves_like :node_set, :length => 1 - - example 'return a Text instance' do - @set[0].is_a?(Oga::XML::Text).should == true - end - - example 'return the "foo" text node' do - @set[0].text.should == 'foo' - end + example 'return a node set containing text nodes' do + evaluate_xpath(@document, 'a/text()').should == node_set(@text1) end - context 'matching nested text nodes' do - before do - @set = @evaluator.evaluate('a/b/text()') - end - - it_behaves_like :node_set, :length => 1 - - example 'return a Text instance' do - @set[0].is_a?(Oga::XML::Text).should == true - end - - example 'return the "bar" text node' do - @set[0].text.should == 'bar' - end + example 'return a node set containing nested text nodes' do + evaluate_xpath(@document, 'a/b/text()').should == node_set(@text2) end end end