require 'spec_helper' <% test.classes.each do |cls| -%> describe "<%= cls.name %>" do <% test.nodes.each do |node| -%> context "using fact set <%= node.name %>" do node_facts = <%= node.fact_set %> let(:facts) { node_facts } <% if node.trusted_set -%> trusted_facts = <%= node.trusted_set %> let(:trusted_facts) { trusted_facts } <% end -%> <% if @before_conditions -%> before :each do <% @before_conditions.each do |function| -%> <%= function %> <% end -%> end <% end -%> <% if @mock_functions -%> # Create a from_json function so that we can parse the output of json for mocked functions before :each do Puppet::Parser::Functions.newfunction(:from_json, :type => :rvalue) { |args| require 'json' JSON.parse(args[0]) } end <% end -%> <% if @after_conditions -%> after :each do <% @after_conditions.each do |function| -%> <%= function %> <% end -%> end <% end -%> let(:pre_condition) { pp = <%= '<<' %>-END $onceover_class = '<%= cls.name %>' $onceover_node = '<%= node.name %>' # Begin user-specified pre_condition <%= (pre_condition || "").chomp %> # End user-specified pre_condition <% if @mock_functions -%> <% require 'json' -%> # Mocking functions <% @mock_functions.each do |function,params| -%> <% if params['returns'].is_a? String -%> <% json = params['returns'].dump[1..-2].to_json -%> <% else -%> <% json = params['returns'].to_json -%> <% end -%> function <%= function %> (*$args) { from_json('<%= json %>') } <% end -%> <% end -%> END } it { should compile } end <% end -%> end <% end -%>