From ac6c0d806e6ef6ad53670fdd82fb635e5baf3371 Mon Sep 17 00:00:00 2001 From: Yorick Peterse Date: Wed, 8 Jul 2015 01:45:26 +0200 Subject: [PATCH] Updated XPath variables spec to use the compiler --- spec/oga/xpath/compiler/variables_spec.rb | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/spec/oga/xpath/compiler/variables_spec.rb b/spec/oga/xpath/compiler/variables_spec.rb index 0528ccf..e3bafbe 100644 --- a/spec/oga/xpath/compiler/variables_spec.rb +++ b/spec/oga/xpath/compiler/variables_spec.rb @@ -1,22 +1,25 @@ require 'spec_helper' describe Oga::XPath::Compiler do - describe 'variable bindings' do + describe 'using variable bindings' do before do @document = parse('') + @compiler = described_class.new end - it 'evaluates a variable' do - evaluator = described_class.new(@document, 'number' => 10.0) + it 'returns the value of a variable' do + ast = parse_xpath('$number') + block = @compiler.compile(ast) - evaluator.evaluate('$number').should == 10.0 + block.call(@document, 'number' => 10.0).should == 10.0 end it 'raises RuntimeError when evaluating an unbound variable' do - evaluator = described_class.new(@document) - block = lambda { evaluator.evaluate('$number') } + ast = parse_xpath('$number') + block = @compiler.compile(ast) - block.should raise_error 'Undefined XPath variable: number' + proc { block.call(@document) }.should + raise_error 'Undefined XPath variable: number' end end end