1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
|
require 'spec_helper'
require 'puppet/parser/ast/block_expression'
describe 'Puppet::Parser::AST::BlockExpression' do
class StackDepthAST < Puppet::Parser::AST
attr_reader :call_depth
def evaluate(*options)
@call_depth = caller.length
end
end
NO_SCOPE = nil
def depth_probe
StackDepthAST.new({})
end
def sequence_probe(name)
probe = double("Sequence Probe #{name}")
expect(probe).to receive(:safeevaluate).ordered
probe
end
def block_of(children)
Puppet::Parser::AST::BlockExpression.new(:children => children)
end
def assert_all_at_same_depth(*probes)
depth0 = probes[0].call_depth
probes.drop(1).each do |p|
expect(p.call_depth).to eq(depth0)
end
end
it "evaluates all its children at the same stack depth" do
depth_probes = [depth_probe, depth_probe]
expr = block_of(depth_probes)
expr.evaluate(NO_SCOPE)
assert_all_at_same_depth(*depth_probes)
end
it "evaluates sequenced children at the same stack depth" do
depth1 = depth_probe
depth2 = depth_probe
depth3 = depth_probe
expr1 = block_of([depth1])
expr2 = block_of([depth2])
expr3 = block_of([depth3])
expr1.sequence_with(expr2).sequence_with(expr3).evaluate(NO_SCOPE)
assert_all_at_same_depth(depth1, depth2, depth3)
end
it "evaluates sequenced children in order" do
expr1 = block_of([sequence_probe("Step 1")])
expr2 = block_of([sequence_probe("Step 2")])
expr3 = block_of([sequence_probe("Step 3")])
expr1.sequence_with(expr2).sequence_with(expr3).evaluate(NO_SCOPE)
end
end
|