diff --git a/spec/oga/xpath/evaluator/operators/add_spec.rb b/spec/oga/xpath/evaluator/operators/add_spec.rb index 8340799..49bef3e 100644 --- a/spec/oga/xpath/evaluator/operators/add_spec.rb +++ b/spec/oga/xpath/evaluator/operators/add_spec.rb @@ -3,32 +3,31 @@ require 'spec_helper' describe Oga::XPath::Evaluator do context 'add operator' do before do - @document = parse('12') - @evaluator = described_class.new(@document) + @document = parse('12') end example 'add two numbers' do - @evaluator.evaluate('1 + 2').should == 3.0 + evaluate_xpath(@document, '1 + 2').should == 3.0 end example 'add a number and a string' do - @evaluator.evaluate('1 + "2"').should == 3.0 + evaluate_xpath(@document, '1 + "2"').should == 3.0 end example 'add two strings' do - @evaluator.evaluate('"1" + "2"').should == 3.0 + evaluate_xpath(@document, '"1" + "2"').should == 3.0 end example 'add a number and a node set' do - @evaluator.evaluate('root/a + 2').should == 3.0 + evaluate_xpath(@document, 'root/a + 2').should == 3.0 end example 'add two node sets' do - @evaluator.evaluate('root/a + root/b').should == 3.0 + evaluate_xpath(@document, 'root/a + root/b').should == 3.0 end example 'return NaN when trying to add invalid values' do - @evaluator.evaluate('"" + 1').should be_nan + evaluate_xpath(@document, '"" + 1').should be_nan end end end diff --git a/spec/oga/xpath/evaluator/operators/and_spec.rb b/spec/oga/xpath/evaluator/operators/and_spec.rb index dede481..1030691 100644 --- a/spec/oga/xpath/evaluator/operators/and_spec.rb +++ b/spec/oga/xpath/evaluator/operators/and_spec.rb @@ -3,30 +3,30 @@ require 'spec_helper' describe Oga::XPath::Evaluator do context 'and operator' do before do - @document = parse('11') - @evaluator = described_class.new(@document) + @document = parse('11') end example 'return true if both boolean literals are true' do - @evaluator.evaluate('true() and true()').should == true + evaluate_xpath(@document, 'true() and true()').should == true end example 'return false if one of the boolean literals is false' do - @evaluator.evaluate('true() and false()').should == false + evaluate_xpath(@document, 'true() and false()').should == false end example 'return true if both node sets are non empty' do - @evaluator.evaluate('root/a and root/b').should == true + evaluate_xpath(@document, 'root/a and root/b').should == true end example 'false false if one of the node sets is empty' do - @evaluator.evaluate('root/a and root/c').should == false + evaluate_xpath(@document, 'root/a and root/c').should == false end example 'skip the right expression if the left one evaluates to false' do - @evaluator.should_not receive(:on_call_true) + evaluator = described_class.new(@document) + evaluator.should_not receive(:on_call_true) - @evaluator.evaluate('false() and true()').should == false + evaluator.evaluate('false() and true()').should == false end end end diff --git a/spec/oga/xpath/evaluator/operators/div_spec.rb b/spec/oga/xpath/evaluator/operators/div_spec.rb index 91d2d07..5eede82 100644 --- a/spec/oga/xpath/evaluator/operators/div_spec.rb +++ b/spec/oga/xpath/evaluator/operators/div_spec.rb @@ -3,32 +3,31 @@ require 'spec_helper' describe Oga::XPath::Evaluator do context 'div operator' do before do - @document = parse('12') - @evaluator = described_class.new(@document) + @document = parse('12') end example 'divide two numbers' do - @evaluator.evaluate('1 div 2').should == 0.5 + evaluate_xpath(@document, '1 div 2').should == 0.5 end example 'divide a number and a string' do - @evaluator.evaluate('1 div "2"').should == 0.5 + evaluate_xpath(@document, '1 div "2"').should == 0.5 end example 'divide two strings' do - @evaluator.evaluate('"1" div "2"').should == 0.5 + evaluate_xpath(@document, '"1" div "2"').should == 0.5 end example 'divide a number and a node set' do - @evaluator.evaluate('root/a div 2').should == 0.5 + evaluate_xpath(@document, 'root/a div 2').should == 0.5 end example 'divide two node sets' do - @evaluator.evaluate('root/a div root/b').should == 0.5 + evaluate_xpath(@document, 'root/a div root/b').should == 0.5 end example 'return NaN when trying to divide invalid values' do - @evaluator.evaluate('"" div 1').should be_nan + evaluate_xpath(@document, '"" div 1').should be_nan end end end diff --git a/spec/oga/xpath/evaluator/operators/eq_spec.rb b/spec/oga/xpath/evaluator/operators/eq_spec.rb index 81836fc..e66e14c 100644 --- a/spec/oga/xpath/evaluator/operators/eq_spec.rb +++ b/spec/oga/xpath/evaluator/operators/eq_spec.rb @@ -3,60 +3,59 @@ require 'spec_helper' describe Oga::XPath::Evaluator do context 'equal operator' do before do - @document = parse('1010') - @evaluator = described_class.new(@document) + @document = parse('1010') end example 'return true if two numbers are equal' do - @evaluator.evaluate('10 = 10').should == true + evaluate_xpath(@document, '10 = 10').should == true end example 'return false if two numbers are not equal' do - @evaluator.evaluate('10 = 15').should == false + evaluate_xpath(@document, '10 = 15').should == false end example 'return true if a number and a string are equal' do - @evaluator.evaluate('10 = "10"').should == true + evaluate_xpath(@document, '10 = "10"').should == true end example 'return true if two strings are equal' do - @evaluator.evaluate('"10" = "10"').should == true + evaluate_xpath(@document, '"10" = "10"').should == true end example 'return true if a string and a number are equal' do - @evaluator.evaluate('"10" = 10').should == true + evaluate_xpath(@document, '"10" = 10').should == true end example 'return false if two strings are not equal' do - @evaluator.evaluate('"a" = "b"').should == false + evaluate_xpath(@document, '"a" = "b"').should == false end example 'return true if two node sets are equal' do - @evaluator.evaluate('root/a = root/b').should == true + evaluate_xpath(@document, 'root/a = root/b').should == true end example 'return false if two node sets are not equal' do - @evaluator.evaluate('root/a = root/c').should == false + evaluate_xpath(@document, 'root/a = root/c').should == false end example 'return true if a node set and a number are equal' do - @evaluator.evaluate('root/a = 10').should == true + evaluate_xpath(@document, 'root/a = 10').should == true end example 'return true if a node set and a string are equal' do - @evaluator.evaluate('root/a = "10"').should == true + evaluate_xpath(@document, 'root/a = "10"').should == true end example 'return true if a node set wildcard and a number are equal' do - @evaluator.evaluate('root/* = 10').should == true + evaluate_xpath(@document, 'root/* = 10').should == true end example 'return true if a number and a node set wildcard are equal' do - @evaluator.evaluate('10 = root/*').should == true + evaluate_xpath(@document, '10 = root/*').should == true end example 'return true if an attribute and string are equal' do - @evaluator.evaluate('root/b/@class = "foo"').should == true + evaluate_xpath(@document, 'root/b/@class = "foo"').should == true end end end diff --git a/spec/oga/xpath/evaluator/operators/gt_spec.rb b/spec/oga/xpath/evaluator/operators/gt_spec.rb index 3605eba..4ea02bb 100644 --- a/spec/oga/xpath/evaluator/operators/gt_spec.rb +++ b/spec/oga/xpath/evaluator/operators/gt_spec.rb @@ -3,40 +3,39 @@ require 'spec_helper' describe Oga::XPath::Evaluator do context 'greater-than operator' do before do - @document = parse('1020') - @evaluator = described_class.new(@document) + @document = parse('1020') end example 'return true if a number is greater than another number' do - @evaluator.evaluate('20 > 10').should == true + evaluate_xpath(@document, '20 > 10').should == true end example 'return false if a number is not greater than another number' do - @evaluator.evaluate('10 > 20').should == false + evaluate_xpath(@document, '10 > 20').should == false end example 'return true if a number is greater than a string' do - @evaluator.evaluate('20 > "10"').should == true + evaluate_xpath(@document, '20 > "10"').should == true end example 'return true if a string is greater than a number' do - @evaluator.evaluate('"20" > 10').should == true + evaluate_xpath(@document, '"20" > 10').should == true end example 'return true if a string is greater than another string' do - @evaluator.evaluate('"20" > "10"').should == true + evaluate_xpath(@document, '"20" > "10"').should == true end example 'return true if a number is greater than a node set' do - @evaluator.evaluate('20 > root/a').should == true + evaluate_xpath(@document, '20 > root/a').should == true end example 'return true if a string is greater than a node set' do - @evaluator.evaluate('"20" > root/a').should == true + evaluate_xpath(@document, '"20" > root/a').should == true end example 'return true if a node set is greater than another node set' do - @evaluator.evaluate('root/b > root/a').should == true + evaluate_xpath(@document, 'root/b > root/a').should == true end end end diff --git a/spec/oga/xpath/evaluator/operators/gte_spec.rb b/spec/oga/xpath/evaluator/operators/gte_spec.rb index 2f9a807..a3278fe 100644 --- a/spec/oga/xpath/evaluator/operators/gte_spec.rb +++ b/spec/oga/xpath/evaluator/operators/gte_spec.rb @@ -3,64 +3,63 @@ require 'spec_helper' describe Oga::XPath::Evaluator do context 'greater-than-or-equal operator' do before do - @document = parse('1020') - @evaluator = described_class.new(@document) + @document = parse('1020') end example 'return true if a number is greater than another number' do - @evaluator.evaluate('20 >= 10').should == true + evaluate_xpath(@document, '20 >= 10').should == true end example 'return true if a number is equal to another number' do - @evaluator.evaluate('10 >= 10').should == true + evaluate_xpath(@document, '10 >= 10').should == true end example 'return false if a number is not greater than/equal to another number' do - @evaluator.evaluate('10 >= 20').should == false + evaluate_xpath(@document, '10 >= 20').should == false end example 'return true if a number is greater than a string' do - @evaluator.evaluate('20 >= "10"').should == true + evaluate_xpath(@document, '20 >= "10"').should == true end example 'return true if a number is equal to a string' do - @evaluator.evaluate('10 >= "10"').should == true + evaluate_xpath(@document, '10 >= "10"').should == true end example 'return true if a string is greater than a number' do - @evaluator.evaluate('"20" >= 10').should == true + evaluate_xpath(@document, '"20" >= 10').should == true end example 'return true if a string is equal to a number' do - @evaluator.evaluate('"10" >= 10').should == true + evaluate_xpath(@document, '"10" >= 10').should == true end example 'return true if a string is greater than another string' do - @evaluator.evaluate('"20" >= "10"').should == true + evaluate_xpath(@document, '"20" >= "10"').should == true end example 'return true if a number is greater than a node set' do - @evaluator.evaluate('20 >= root/a').should == true + evaluate_xpath(@document, '20 >= root/a').should == true end example 'return true if a number is equal to a node set' do - @evaluator.evaluate('20 >= root/b').should == true + evaluate_xpath(@document, '20 >= root/b').should == true end example 'return true if a string is greater than a node set' do - @evaluator.evaluate('"20" >= root/a').should == true + evaluate_xpath(@document, '"20" >= root/a').should == true end example 'return true if a string is equal to a node set' do - @evaluator.evaluate('"10" >= root/a').should == true + evaluate_xpath(@document, '"10" >= root/a').should == true end example 'return true if a node set is greater than another node set' do - @evaluator.evaluate('root/b >= root/a').should == true + evaluate_xpath(@document, 'root/b >= root/a').should == true end example 'return true if a node set is equal to another node set' do - @evaluator.evaluate('root/b >= root/b').should == true + evaluate_xpath(@document, 'root/b >= root/b').should == true end end end diff --git a/spec/oga/xpath/evaluator/operators/lt_spec.rb b/spec/oga/xpath/evaluator/operators/lt_spec.rb index fed96dc..210b4ba 100644 --- a/spec/oga/xpath/evaluator/operators/lt_spec.rb +++ b/spec/oga/xpath/evaluator/operators/lt_spec.rb @@ -3,40 +3,39 @@ require 'spec_helper' describe Oga::XPath::Evaluator do context 'lower-than operator' do before do - @document = parse('1020') - @evaluator = described_class.new(@document) + @document = parse('1020') end example 'return true if a number is lower than another number' do - @evaluator.evaluate('10 < 20').should == true + evaluate_xpath(@document, '10 < 20').should == true end example 'return false if a number is not lower than another number' do - @evaluator.evaluate('20 < 10').should == false + evaluate_xpath(@document, '20 < 10').should == false end example 'return true if a number is lower than a string' do - @evaluator.evaluate('10 < "20"').should == true + evaluate_xpath(@document, '10 < "20"').should == true end example 'return true if a string is lower than a number' do - @evaluator.evaluate('"10" < 20').should == true + evaluate_xpath(@document, '"10" < 20').should == true end example 'return true if a string is lower than another string' do - @evaluator.evaluate('"10" < "20"').should == true + evaluate_xpath(@document, '"10" < "20"').should == true end example 'return true if a number is lower than a node set' do - @evaluator.evaluate('10 < root/b').should == true + evaluate_xpath(@document, '10 < root/b').should == true end example 'return true if a string is lower than a node set' do - @evaluator.evaluate('"10" < root/b').should == true + evaluate_xpath(@document, '"10" < root/b').should == true end example 'return true if a node set is lower than another node set' do - @evaluator.evaluate('root/a < root/b').should == true + evaluate_xpath(@document, 'root/a < root/b').should == true end end end diff --git a/spec/oga/xpath/evaluator/operators/lte_spec.rb b/spec/oga/xpath/evaluator/operators/lte_spec.rb index 89ae29d..e598a95 100644 --- a/spec/oga/xpath/evaluator/operators/lte_spec.rb +++ b/spec/oga/xpath/evaluator/operators/lte_spec.rb @@ -3,64 +3,63 @@ require 'spec_helper' describe Oga::XPath::Evaluator do context 'lower-than-or-equal operator' do before do - @document = parse('1020') - @evaluator = described_class.new(@document) + @document = parse('1020') end example 'return true if a number is lower than another number' do - @evaluator.evaluate('10 <= 20').should == true + evaluate_xpath(@document, '10 <= 20').should == true end example 'return true if a number is equal to another number' do - @evaluator.evaluate('10 <= 10').should == true + evaluate_xpath(@document, '10 <= 10').should == true end example 'return false if a number is not lower than/equal to another number' do - @evaluator.evaluate('20 <= 10').should == false + evaluate_xpath(@document, '20 <= 10').should == false end example 'return true if a number is lower than a string' do - @evaluator.evaluate('10 <= "20"').should == true + evaluate_xpath(@document, '10 <= "20"').should == true end example 'return true if a number is equal to a string' do - @evaluator.evaluate('10 <= "10"').should == true + evaluate_xpath(@document, '10 <= "10"').should == true end example 'return true if a string is lower than a number' do - @evaluator.evaluate('"10" <= 20').should == true + evaluate_xpath(@document, '"10" <= 20').should == true end example 'return true if a string is equal to a number' do - @evaluator.evaluate('"10" <= 10').should == true + evaluate_xpath(@document, '"10" <= 10').should == true end example 'return true if a string is lower than another string' do - @evaluator.evaluate('"10" <= "20"').should == true + evaluate_xpath(@document, '"10" <= "20"').should == true end example 'return true if a number is lower than a node set' do - @evaluator.evaluate('10 <= root/b').should == true + evaluate_xpath(@document, '10 <= root/b').should == true end example 'return true if a number is equal to a node set' do - @evaluator.evaluate('10 <= root/a').should == true + evaluate_xpath(@document, '10 <= root/a').should == true end example 'return true if a string is lower than a node set' do - @evaluator.evaluate('"10" <= root/b').should == true + evaluate_xpath(@document, '"10" <= root/b').should == true end example 'return true if a string is equal to a node set' do - @evaluator.evaluate('"10" <= root/a').should == true + evaluate_xpath(@document, '"10" <= root/a').should == true end example 'return true if a node set is lower than another node set' do - @evaluator.evaluate('root/a <= root/b').should == true + evaluate_xpath(@document, 'root/a <= root/b').should == true end example 'return true if a node set is equal to another node set' do - @evaluator.evaluate('root/b <= root/b').should == true + evaluate_xpath(@document, 'root/b <= root/b').should == true end end end diff --git a/spec/oga/xpath/evaluator/operators/mod_spec.rb b/spec/oga/xpath/evaluator/operators/mod_spec.rb index 53ce250..d8c7fc0 100644 --- a/spec/oga/xpath/evaluator/operators/mod_spec.rb +++ b/spec/oga/xpath/evaluator/operators/mod_spec.rb @@ -3,32 +3,31 @@ require 'spec_helper' describe Oga::XPath::Evaluator do context 'mod operator' do before do - @document = parse('23') - @evaluator = described_class.new(@document) + @document = parse('23') end example 'return the modulo of two numbers' do - @evaluator.evaluate('2 mod 3').should == 2.0 + evaluate_xpath(@document, '2 mod 3').should == 2.0 end example 'return the modulo of a number and a string' do - @evaluator.evaluate('2 mod "3"').should == 2.0 + evaluate_xpath(@document, '2 mod "3"').should == 2.0 end example 'return the modulo of two strings' do - @evaluator.evaluate('"2" mod "3"').should == 2.0 + evaluate_xpath(@document, '"2" mod "3"').should == 2.0 end example 'return the modulo of a node set and a number' do - @evaluator.evaluate('root/a mod 3').should == 2.0 + evaluate_xpath(@document, 'root/a mod 3').should == 2.0 end example 'return the modulo of two node sets' do - @evaluator.evaluate('root/a mod root/b').should == 2.0 + evaluate_xpath(@document, 'root/a mod root/b').should == 2.0 end example 'return NaN when trying to get the modulo of invalid values' do - @evaluator.evaluate('"" mod 1').should be_nan + evaluate_xpath(@document, '"" mod 1').should be_nan end end end diff --git a/spec/oga/xpath/evaluator/operators/mul_spec.rb b/spec/oga/xpath/evaluator/operators/mul_spec.rb index 60f3b17..b29e960 100644 --- a/spec/oga/xpath/evaluator/operators/mul_spec.rb +++ b/spec/oga/xpath/evaluator/operators/mul_spec.rb @@ -3,32 +3,31 @@ require 'spec_helper' describe Oga::XPath::Evaluator do context 'multiplication operator' do before do - @document = parse('23') - @evaluator = described_class.new(@document) + @document = parse('23') end example 'multiply two numbers' do - @evaluator.evaluate('2 * 3').should == 6.0 + evaluate_xpath(@document, '2 * 3').should == 6.0 end example 'multiply a number and a string' do - @evaluator.evaluate('2 * "3"').should == 6.0 + evaluate_xpath(@document, '2 * "3"').should == 6.0 end example 'multiply two strings' do - @evaluator.evaluate('"2" * "3"').should == 6.0 + evaluate_xpath(@document, '"2" * "3"').should == 6.0 end example 'multiply a node set and a number' do - @evaluator.evaluate('root/a * 3').should == 6.0 + evaluate_xpath(@document, 'root/a * 3').should == 6.0 end example 'multiply two node sets' do - @evaluator.evaluate('root/a * root/b').should == 6.0 + evaluate_xpath(@document, 'root/a * root/b').should == 6.0 end example 'return NaN when trying to multiply invalid values' do - @evaluator.evaluate('"" * 1').should be_nan + evaluate_xpath(@document, '"" * 1').should be_nan end end end diff --git a/spec/oga/xpath/evaluator/operators/neq_spec.rb b/spec/oga/xpath/evaluator/operators/neq_spec.rb index 9e2d55b..d406ef0 100644 --- a/spec/oga/xpath/evaluator/operators/neq_spec.rb +++ b/spec/oga/xpath/evaluator/operators/neq_spec.rb @@ -3,48 +3,47 @@ require 'spec_helper' describe Oga::XPath::Evaluator do context 'not-equal operator' do before do - @document = parse('1010') - @evaluator = described_class.new(@document) + @document = parse('1010') end example 'return true if two numbers are not equal' do - @evaluator.evaluate('10 != 20').should == true + evaluate_xpath(@document, '10 != 20').should == true end example 'return false if two numbers are equal' do - @evaluator.evaluate('10 != 10').should == false + evaluate_xpath(@document, '10 != 10').should == false end example 'return true if a number and a string are not equal' do - @evaluator.evaluate('10 != "20"').should == true + evaluate_xpath(@document, '10 != "20"').should == true end example 'return true if two strings are not equal' do - @evaluator.evaluate('"10" != "20"').should == true + evaluate_xpath(@document, '"10" != "20"').should == true end example 'return true if a string and a number are not equal' do - @evaluator.evaluate('"10" != 20').should == true + evaluate_xpath(@document, '"10" != 20').should == true end example 'return false if two strings are equal' do - @evaluator.evaluate('"a" != "a"').should == false + evaluate_xpath(@document, '"a" != "a"').should == false end example 'return true if two node sets are not equal' do - @evaluator.evaluate('root != root/b').should == true + evaluate_xpath(@document, 'root != root/b').should == true end example 'return false if two node sets are equal' do - @evaluator.evaluate('root/a != root/b').should == false + evaluate_xpath(@document, 'root/a != root/b').should == false end example 'return true if a node set and a number are not equal' do - @evaluator.evaluate('root/a != 20').should == true + evaluate_xpath(@document, 'root/a != 20').should == true end example 'return true if a node set and a string are not equal' do - @evaluator.evaluate('root/a != "20"').should == true + evaluate_xpath(@document, 'root/a != "20"').should == true end end end diff --git a/spec/oga/xpath/evaluator/operators/or_spec.rb b/spec/oga/xpath/evaluator/operators/or_spec.rb index 28a2563..fe9456f 100644 --- a/spec/oga/xpath/evaluator/operators/or_spec.rb +++ b/spec/oga/xpath/evaluator/operators/or_spec.rb @@ -3,38 +3,38 @@ require 'spec_helper' describe Oga::XPath::Evaluator do context 'or operator' do before do - @document = parse('11') - @evaluator = described_class.new(@document) + @document = parse('11') end example 'return true if both boolean literals are true' do - @evaluator.evaluate('true() or true()').should == true + evaluate_xpath(@document, 'true() or true()').should == true end example 'return true if one of the boolean literals is false' do - @evaluator.evaluate('true() or false()').should == true + evaluate_xpath(@document, 'true() or false()').should == true end example 'return true if the left node set is not empty' do - @evaluator.evaluate('root/a or root/x').should == true + evaluate_xpath(@document, 'root/a or root/x').should == true end example 'return true if the right node set is not empty' do - @evaluator.evaluate('root/x or root/b').should == true + evaluate_xpath(@document, 'root/x or root/b').should == true end example 'return true if both node sets are not empty' do - @evaluator.evaluate('root/a or root/b').should == true + evaluate_xpath(@document, 'root/a or root/b').should == true end example 'return false if both node sets are empty' do - @evaluator.evaluate('root/x or root/y').should == false + evaluate_xpath(@document, 'root/x or root/y').should == false end example 'skip the right expression if the left one evaluates to false' do - @evaluator.should_not receive(:on_call_false) + evaluator = described_class.new(@document) + evaluator.should_not receive(:on_call_false) - @evaluator.evaluate('true() or false()').should == true + evaluator.evaluate('true() or false()').should == true end end end diff --git a/spec/oga/xpath/evaluator/operators/pipe_spec.rb b/spec/oga/xpath/evaluator/operators/pipe_spec.rb index 1c886fd..4644945 100644 --- a/spec/oga/xpath/evaluator/operators/pipe_spec.rb +++ b/spec/oga/xpath/evaluator/operators/pipe_spec.rb @@ -3,60 +3,26 @@ require 'spec_helper' describe Oga::XPath::Evaluator do context 'pipe operator' do before do - @document = parse('') - @evaluator = described_class.new(@document) + @document = parse('') + + @a1 = @document.children[0].children[0] + @b1 = @document.children[0].children[1] end - context 'merge two sets' do - before do - @set = @evaluator.evaluate('/root/a | /root/b') - end - - it_behaves_like :node_set, :length => 2 - - example 'include the node' do - @set[0].name.should == 'a' - end - - example 'include the node' do - @set[1].name.should == 'b' - end + example 'merge two node sets' do + evaluate_xpath(@document, 'root/a | root/b').should == node_set(@a1, @b1) end - context 'merge two sets when the left hand side is empty' do - before do - @set = @evaluator.evaluate('foo | /root/b') - end - - it_behaves_like :node_set, :length => 1 - - example 'include the node' do - @set[0].name.should == 'b' - end + example 'merge two sets when the left hand side is empty' do + evaluate_xpath(@document, 'foo | root/b').should == node_set(@b1) end - context 'merge two sets when the right hand side is empty' do - before do - @set = @evaluator.evaluate('/root/a | foo') - end - - it_behaves_like :node_set, :length => 1 - - example 'include the node' do - @set[0].name.should == 'a' - end + example 'merge two sets when the right hand side is empty' do + evaluate_xpath(@document, 'root/a | foo').should == node_set(@a1) end - context 'merge two identical sets' do - before do - @set = @evaluator.evaluate('/root/a | /root/a') - end - - it_behaves_like :node_set, :length => 1 - - example 'include only a single node' do - @set[0].name.should == 'a' - end + example 'merge two identical sets' do + evaluate_xpath(@document, 'root/a | root/a').should == node_set(@a1) end end end diff --git a/spec/oga/xpath/evaluator/operators/sub_spec.rb b/spec/oga/xpath/evaluator/operators/sub_spec.rb index bc2d602..5fd9ab6 100644 --- a/spec/oga/xpath/evaluator/operators/sub_spec.rb +++ b/spec/oga/xpath/evaluator/operators/sub_spec.rb @@ -3,32 +3,31 @@ require 'spec_helper' describe Oga::XPath::Evaluator do context 'subtraction operator' do before do - @document = parse('23') - @evaluator = described_class.new(@document) + @document = parse('23') end example 'subtract two numbers' do - @evaluator.evaluate('2 - 3').should == -1.0 + evaluate_xpath(@document, '2 - 3').should == -1.0 end example 'subtract a number and a string' do - @evaluator.evaluate('2 - "3"').should == -1.0 + evaluate_xpath(@document, '2 - "3"').should == -1.0 end example 'subtract two strings' do - @evaluator.evaluate('"2" - "3"').should == -1.0 + evaluate_xpath(@document, '"2" - "3"').should == -1.0 end example 'subtract a node set and a number' do - @evaluator.evaluate('root/a - 3').should == -1.0 + evaluate_xpath(@document, 'root/a - 3').should == -1.0 end example 'subtract two node sets' do - @evaluator.evaluate('root/a - root/b').should == -1.0 + evaluate_xpath(@document, 'root/a - root/b').should == -1.0 end example 'return NaN when trying to subtract invalid values' do - @evaluator.evaluate('"" - 1').should be_nan + evaluate_xpath(@document, '"" - 1').should be_nan end end end