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

View File

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

View File

@ -7,6 +7,7 @@ end
require_relative '../lib/oga'
require_relative 'support/parsing'
require_relative 'support/shared_examples'
RSpec.configure do |config|
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