Sha256: 8d41401128a153ab38c17d34f04c83f6c0b0dcc3888c6a05d10eb049c04c41b4

Contents?: true

Size: 1.17 KB

Versions: 34

Compression:

Stored size: 1.17 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, 'command', '')
      end

      # Public methods

      def with_params(params)
        @invocation[:options] = params.select { |k, _v| k.start_with?('_') }
                                      .transform_keys { |k| k.sub(/^_/, '').to_sym }
        self
      end
    end
  end
end

Version data entries

34 entries across 34 versions & 1 rubygems

Version Path
bolt-2.32.0 lib/bolt_spec/plans/action_stubs/command_stub.rb
bolt-2.31.0 lib/bolt_spec/plans/action_stubs/command_stub.rb
bolt-2.30.0 lib/bolt_spec/plans/action_stubs/command_stub.rb
bolt-2.29.0 lib/bolt_spec/plans/action_stubs/command_stub.rb
bolt-2.28.0 lib/bolt_spec/plans/action_stubs/command_stub.rb
bolt-2.27.0 lib/bolt_spec/plans/action_stubs/command_stub.rb
bolt-2.26.0 lib/bolt_spec/plans/action_stubs/command_stub.rb
bolt-2.25.0 lib/bolt_spec/plans/action_stubs/command_stub.rb
bolt-2.24.1 lib/bolt_spec/plans/action_stubs/command_stub.rb
bolt-2.24.0 lib/bolt_spec/plans/action_stubs/command_stub.rb
bolt-2.23.0 lib/bolt_spec/plans/action_stubs/command_stub.rb
bolt-2.22.0 lib/bolt_spec/plans/action_stubs/command_stub.rb
bolt-2.21.0 lib/bolt_spec/plans/action_stubs/command_stub.rb
bolt-2.20.0 lib/bolt_spec/plans/action_stubs/command_stub.rb
bolt-2.19.0 lib/bolt_spec/plans/action_stubs/command_stub.rb
bolt-2.18.0 lib/bolt_spec/plans/action_stubs/command_stub.rb
bolt-2.17.0 lib/bolt_spec/plans/action_stubs/command_stub.rb
bolt-2.16.0 lib/bolt_spec/plans/action_stubs/command_stub.rb
bolt-2.15.0 lib/bolt_spec/plans/action_stubs/command_stub.rb
bolt-2.14.0 lib/bolt_spec/plans/action_stubs/command_stub.rb