Added XPath::Compiler.compile_with_cache

This commit is contained in:
Yorick Peterse committed 2015-08-19 20:14:20 +02:00
1 parent 6d01adafc7
commit 3300a6df49
2 files changed
+38 -4

No files matched your search

+26 -4
View File
@@ -5,6 +5,32 @@ describe Oga::XPath::Compiler do
@compiler = described_class.new
end
describe 'compile_with_cache' do
before do
described_class::CACHE.clear
end
it 'returns a Proc as a lambda' do
ast = parse_xpath('foo')
block = described_class.compile_with_cache(ast)
block.should be_an_instance_of(Proc)
block.lambda?.should == true
end
it 'caches a compiled Proc' do
ast = parse_xpath('foo')
described_class.any_instance
.should_receive(:compile)
.once
.and_call_original
described_class.compile_with_cache(ast).should be_an_instance_of(Proc)
described_class.compile_with_cache(ast).should be_an_instance_of(Proc)
end
end
describe '#compile' do
it 'returns a Proc as a lambda' do
ast = parse_xpath('foo')
@@ -21,10 +47,6 @@ describe Oga::XPath::Compiler do
@compiler.compile(ast).arity.should == 1
end
xit 'caches a compiled Proc for a given XPath AST' do
# TODO
end
describe 'calling the compiled Proc' do
it 'returns a NodeSet' do
doc = parse('<foo></foo>')