lib/bolt_spec/plans.rb in bolt-1.31.1 vs lib/bolt_spec/plans.rb in bolt-1.32.0

- old
+ new

@@ -61,10 +61,12 @@ # - allow_script(script), expect_script(script): expect the script as <module>/path/to/file # - allow_task(task), expect_task(task): expect the named task # - allow_upload(file), expect_upload(file): expect the identified source file # - allow_apply_prep: allows `apply_prep` to be invoked in the plan but does not allow modifiers # - allow_apply: allows `apply` to be invoked in the plan but does not allow modifiers +# - allow_out_message, expect_out_message: expect a message to be passed to out::message (only modifiers are +# be_called_times(n), with_params(params), and not_be_called) # # Stub modifiers: # - be_called_times(n): if allowed, fail if the action is called more than 'n' times # if expected, fail unless the action is called 'n' times # - not_be_called: fail if the action is called @@ -126,10 +128,16 @@ # expect_task('my_task').return do |targets:, task:, params:| # Bolt::ResultSet.new(targets.map { |targ| Bolt::Result.new(targ, {'result_key' => 10'})}) # end # expect(run_plan('my_plan', { 'param1' => 10 })).to eq(10) # end + +# it 'expects multiple messages to out::message' do +# expect_out_message.be_called_times(2).with_params(message) +# result = run_plan(plan_name, 'messages' => [message, message]) +# expect(result).to be_ok +# end # end # # See spec/bolt_spec/plan_spec.rb for more examples. module BoltSpec module Plans @@ -170,11 +178,11 @@ def puppetdb_client @puppetdb_client ||= MockPuppetDBClient.new end def run_plan(name, params) - pal = Bolt::PAL.new(config.modulepath, config.hiera_config) + pal = Bolt::PAL.new(config.modulepath, config.hiera_config, config.boltdir.resource_types) result = pal.run_plan(name, params, executor, inventory, puppetdb_client) if executor.error_message raise executor.error_message end @@ -217,9 +225,18 @@ end def allow_get_resources allow_task('apply_helpers::query_resources') nil + end + + def allow_out_message + executor.stub_out_message.add_stub + end + alias allow_any_out_message allow_out_message + + def expect_out_message + allow_out_message.expect_call end # Example helpers to mock other run functions # The with_targets method makes sense for all stubs # with_params could be reused for options