Sha256: aae50f914f917adbc00b779dc1be708a298fd129f1f164a7680116d645822cf6

Contents?: true

Size: 1.37 KB

Versions: 69

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

69 entries across 69 versions & 1 rubygems

Version Path
bolt-3.22.1 lib/bolt_spec/plans/action_stubs/plan_stub.rb
bolt-3.22.0 lib/bolt_spec/plans/action_stubs/plan_stub.rb
bolt-3.21.0 lib/bolt_spec/plans/action_stubs/plan_stub.rb
bolt-3.20.0 lib/bolt_spec/plans/action_stubs/plan_stub.rb
bolt-3.19.0 lib/bolt_spec/plans/action_stubs/plan_stub.rb
bolt-3.18.0 lib/bolt_spec/plans/action_stubs/plan_stub.rb
bolt-3.17.0 lib/bolt_spec/plans/action_stubs/plan_stub.rb
bolt-3.16.1 lib/bolt_spec/plans/action_stubs/plan_stub.rb
bolt-3.16.0 lib/bolt_spec/plans/action_stubs/plan_stub.rb
bolt-3.15.0 lib/bolt_spec/plans/action_stubs/plan_stub.rb
bolt-3.14.1 lib/bolt_spec/plans/action_stubs/plan_stub.rb
bolt-3.13.0 lib/bolt_spec/plans/action_stubs/plan_stub.rb
bolt-3.12.0 lib/bolt_spec/plans/action_stubs/plan_stub.rb
bolt-3.11.0 lib/bolt_spec/plans/action_stubs/plan_stub.rb
bolt-3.10.0 lib/bolt_spec/plans/action_stubs/plan_stub.rb
bolt-3.9.2 lib/bolt_spec/plans/action_stubs/plan_stub.rb
bolt-3.9.1 lib/bolt_spec/plans/action_stubs/plan_stub.rb
bolt-3.9.0 lib/bolt_spec/plans/action_stubs/plan_stub.rb
bolt-3.8.1 lib/bolt_spec/plans/action_stubs/plan_stub.rb
bolt-3.8.0 lib/bolt_spec/plans/action_stubs/plan_stub.rb