Updated XPath variables spec to use the compiler
This commit is contained in:
parent
ebcadd1cb8
commit
ac6c0d806e
|
@ -1,22 +1,25 @@
|
||||||
require 'spec_helper'
|
require 'spec_helper'
|
||||||
|
|
||||||
describe Oga::XPath::Compiler do
|
describe Oga::XPath::Compiler do
|
||||||
describe 'variable bindings' do
|
describe 'using variable bindings' do
|
||||||
before do
|
before do
|
||||||
@document = parse('<a></a>')
|
@document = parse('<a></a>')
|
||||||
|
@compiler = described_class.new
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'evaluates a variable' do
|
it 'returns the value of a variable' do
|
||||||
evaluator = described_class.new(@document, 'number' => 10.0)
|
ast = parse_xpath('$number')
|
||||||
|
block = @compiler.compile(ast)
|
||||||
|
|
||||||
evaluator.evaluate('$number').should == 10.0
|
block.call(@document, 'number' => 10.0).should == 10.0
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'raises RuntimeError when evaluating an unbound variable' do
|
it 'raises RuntimeError when evaluating an unbound variable' do
|
||||||
evaluator = described_class.new(@document)
|
ast = parse_xpath('$number')
|
||||||
block = lambda { evaluator.evaluate('$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
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue