Cleaned up XPath specs using a shared example.

This commit is contained in:
Yorick Peterse 2014-07-15 09:34:11 +02:00
parent 0211f60826
commit 580856dcf7
4 changed files with 20 additions and 46 deletions

View File

@ -11,13 +11,7 @@ describe Oga::XPath::Evaluator do
@set = @evaluator.evaluate('/a') @set = @evaluator.evaluate('/a')
end end
example 'return a NodeSet instance' do it_behaves_like :node_set, :length => 1
@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 example 'return the correct nodes' do
@set[0].should == @document.children[0] @set[0].should == @document.children[0]
@ -29,9 +23,7 @@ describe Oga::XPath::Evaluator do
@set = @evaluator.evaluate('/x/a') @set = @evaluator.evaluate('/x/a')
end end
example 'return an empty NodeSet' do it_behaves_like :node_set, :length => 0
@set.empty?.should == true
end
end end
context 'relative paths' do context 'relative paths' do
@ -39,13 +31,7 @@ describe Oga::XPath::Evaluator do
@set = @evaluator.evaluate('a') @set = @evaluator.evaluate('a')
end end
example 'return a NodeSet instance' do it_behaves_like :node_set, :length => 1
@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 example 'return the correct nodes' do
@set[0].should == @document.children[0] @set[0].should == @document.children[0]
@ -57,9 +43,7 @@ describe Oga::XPath::Evaluator do
@set = @evaluator.evaluate('x/a') @set = @evaluator.evaluate('x/a')
end end
example 'return an empty NodeSet' do it_behaves_like :node_set, :length => 0
@set.empty?.should == true
end
end end
context 'nested paths' do context 'nested paths' do
@ -67,13 +51,7 @@ describe Oga::XPath::Evaluator do
@set = @evaluator.evaluate('/a/b') @set = @evaluator.evaluate('/a/b')
end end
example 'return a NodeSet instance' do it_behaves_like :node_set, :length => 2
@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 example 'return the correct nodes' do
a = @document.children[0] a = @document.children[0]
@ -88,13 +66,7 @@ describe Oga::XPath::Evaluator do
@set = @evaluator.evaluate('a/ns1:c') @set = @evaluator.evaluate('a/ns1:c')
end end
example 'return a NodeSet instance' do it_behaves_like :node_set, :length => 1
@set.is_a?(Oga::XML::NodeSet).should == true
end
example 'return the right amount of rows' do
@set.length.should == 1
end
example 'return the correct row' do example 'return the correct row' do
a = @document.children[0] a = @document.children[0]

View File

@ -11,9 +11,7 @@ describe Oga::XPath::Evaluator do
@set = @evaluator.evaluate('a/*') @set = @evaluator.evaluate('a/*')
end end
example 'return the right amount of rows' do it_behaves_like :node_set, :length => 3
@set.length.should == 3
end
example 'include the first <b> node' do example 'include the first <b> node' do
@set[0].name.should == 'b' @set[0].name.should == 'b'
@ -34,9 +32,7 @@ describe Oga::XPath::Evaluator do
@set = @evaluator.evaluate('a/*:b') @set = @evaluator.evaluate('a/*:b')
end end
example 'return the right amount of rows' do it_behaves_like :node_set, :length => 2
@set.length.should == 2
end
example 'include the first <b> node' do example 'include the first <b> node' do
@set[0].name.should == 'b' @set[0].name.should == 'b'
@ -56,9 +52,7 @@ describe Oga::XPath::Evaluator do
@set = @evaluator.evaluate('a/ns1:*') @set = @evaluator.evaluate('a/ns1:*')
end end
example 'return the right amount of rows' do it_behaves_like :node_set, :length => 1
@set.length.should == 1
end
example 'include the correct <c> node' do example 'include the correct <c> node' do
@set[0].name.should == 'c' @set[0].name.should == 'c'
@ -71,9 +65,7 @@ describe Oga::XPath::Evaluator do
@set = @evaluator.evaluate('a/*:*') @set = @evaluator.evaluate('a/*:*')
end end
example 'return the right amount of rows' do it_behaves_like :node_set, :length => 3
@set.length.should == 3
end
example 'include the first <b> node' do example 'include the first <b> node' do
@set[0].name.should == 'b' @set[0].name.should == 'b'

View File

@ -7,6 +7,7 @@ end
require_relative '../lib/oga' require_relative '../lib/oga'
require_relative 'support/parsing' require_relative 'support/parsing'
require_relative 'support/shared_examples'
RSpec.configure do |config| RSpec.configure do |config|
config.color = true config.color = true

View File

@ -0,0 +1,9 @@
shared_examples :node_set do |options|
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 == options[:length]
end
end