Sha256: 29f22c88beb00bca0b5b8b5211495e05afdbbfcf3c30d35bf846460f86cead2d

Contents?: true

Size: 1.37 KB

Versions: 11

Compression:

Stored size: 1.37 KB

Contents

# frozen_string_literal: true

module BoltSpec
  module Plans
    class PlanStub < ActionStub
      def matches(_scope, _plan, params)
        targets = params.fetch('nodes', params.fetch('targets', nil))
        if @invocation[:targets] && Set.new(@invocation[:targets]) != Set.new(targets)
          return false
        end

        if @invocation[:params] && params != @invocation[:params]
          return false
        end

        true
      end

      def call(_scope, plan, params)
        @calls += 1
        if @return_block
          check_plan_result(@return_block.call(plan: plan, params: params), plan)
        else
          default_for(nil)
        end
      end

      def parameters
        @invocation[:params]
      end

      # Allow any data.
      def result_for(_target, **data)
        Bolt::PlanResult.new(Bolt::Util.walk_keys(data, &:to_s), 'success')
      end

      # Public methods

      # Restricts the stub to only match invocations with certain parameters.
      # All parameters must match exactly.
      def with_params(params)
        @invocation[:params] = params
        self
      end

      def return_for_targets(_data)
        raise "return_for_targets is not implemented for plan spec tests (allow_plan, expect_plan, allow_any_plan, etc)"
      end

      def error_with(data, clazz = Bolt::PlanFailure)
        super(data, clazz)
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
bolt-3.29.0 lib/bolt_spec/plans/action_stubs/plan_stub.rb
bolt-3.28.0 lib/bolt_spec/plans/action_stubs/plan_stub.rb
bolt-3.27.4 lib/bolt_spec/plans/action_stubs/plan_stub.rb
bolt-3.27.2 lib/bolt_spec/plans/action_stubs/plan_stub.rb
bolt-3.27.1 lib/bolt_spec/plans/action_stubs/plan_stub.rb
bolt-3.26.2 lib/bolt_spec/plans/action_stubs/plan_stub.rb
bolt-3.26.1 lib/bolt_spec/plans/action_stubs/plan_stub.rb
bolt-3.25.0 lib/bolt_spec/plans/action_stubs/plan_stub.rb
bolt-3.24.0 lib/bolt_spec/plans/action_stubs/plan_stub.rb
bolt-3.23.1 lib/bolt_spec/plans/action_stubs/plan_stub.rb
bolt-3.23.0 lib/bolt_spec/plans/action_stubs/plan_stub.rb