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 'multi_json' MultiJson.load(args[0]) } end <% end -%> before :each do # Curtrently there is some code within Puppet that will try to execute # commands when compiling a catalog even though it shouldn't. One example is # the groups attribute of the user resource on AIX. If we are running on # Windows but pretending to be UNIX this will definitely fail so we need to # mock it (or vice versa) # Details: # https://github.com/puppetlabs/puppet/blob/master/lib/puppet/util/execution.rb#L191 expected_null_file = Puppet::Util::Platform.windows? ? 'NUL' : '/dev/null' unless File.exist? expected_null_file Puppet::Util::Execution.stubs(:execute).raises(Puppet::ExecutionFailure.new("Onceover caused this")) 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 'multi_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 -%>