Sha256: fa89b488796ef88fdbc2acc244d9d431279f80311a01b612305e9832d86bfbea

Contents?: true

Size: 1.03 KB

Versions: 13

Compression:

Stored size: 1.03 KB

Contents

# frozen_string_literal: true

module BoltSpec
  module Plans
    class CommandStub < ActionStub
      def matches(targets, _command, options)
        if @invocation[:targets] && Set.new(@invocation[:targets]) != Set.new(targets.map(&:name))
          return false
        end

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

        true
      end

      def call(targets, command, options)
        @calls += 1
        if @return_block
          check_resultset(@return_block.call(targets: targets, command: command, params: options), command)
        else
          Bolt::ResultSet.new(targets.map { |target| @data[target.name] || default_for(target) })
        end
      end

      def parameters
        @invocation[:options]
      end

      def result_for(target, stdout: '', stderr: '')
        Bolt::Result.for_command(target, stdout, stderr, 0)
      end

      # Public methods

      def with_params(params)
        @invocation[:options] = params
        self
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
bolt-1.14.0 lib/bolt_spec/plans/action_stubs/command_stub.rb
bolt-1.13.1 lib/bolt_spec/plans/action_stubs/command_stub.rb
bolt-1.13.0 lib/bolt_spec/plans/action_stubs/command_stub.rb
bolt-1.12.0 lib/bolt_spec/plans/action_stubs/command_stub.rb
bolt-1.11.0 lib/bolt_spec/plans/action_stubs/command_stub.rb
bolt-1.10.0 lib/bolt_spec/plans/action_stubs/command_stub.rb
bolt-1.9.0 lib/bolt_spec/plans/action_stubs/command_stub.rb
bolt-1.8.1 lib/bolt_spec/plans/action_stubs/command_stub.rb
bolt-1.8.0 lib/bolt_spec/plans/action_stubs/command_stub.rb
bolt-1.7.0 lib/bolt_spec/plans/action_stubs/command_stub.rb
bolt-1.6.0 lib/bolt_spec/plans/action_stubs/command_stub.rb
bolt-1.5.0 lib/bolt_spec/plans/action_stubs/command_stub.rb
bolt-1.4.0 lib/bolt_spec/plans/action_stubs/command_stub.rb