Sha256: ce80f1b7c7fdcbac5ee3b8cbc136334e687abf2aa941389b71ddbcbc61ddc9c3

Contents?: true

Size: 1.57 KB

Versions: 35

Compression:

Stored size: 1.57 KB

Contents

# frozen_string_literal: true

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

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

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

        true
      end

      def call(targets, source, destination, options)
        @calls += 1
        if @return_block
          results = @return_block.call(targets: targets, source: source, destination: destination, params: options)
          check_resultset(results, source)
        else
          results = targets.map do |target|
            if @data[:default].is_a?(Bolt::Error)
              default_for(target)
            else
              Bolt::Result.for_upload(target, source, destination)
            end
          end
          Bolt::ResultSet.new(results)
        end
      end

      def parameters
        @invocation[:options]
      end

      def result_for(_target, _data)
        raise 'Upload result cannot be changed'
      end

      # Public methods

      def always_return(_data)
        raise 'Upload result cannot be changed'
      end

      def with_destination(destination)
        @invocation[:destination] = destination
        self
      end

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

Version data entries

35 entries across 35 versions & 1 rubygems

Version Path
bolt-1.32.0 lib/bolt_spec/plans/action_stubs/upload_stub.rb
bolt-1.31.1 lib/bolt_spec/plans/action_stubs/upload_stub.rb
bolt-1.31.0 lib/bolt_spec/plans/action_stubs/upload_stub.rb
bolt-1.30.1 lib/bolt_spec/plans/action_stubs/upload_stub.rb
bolt-1.30.0 lib/bolt_spec/plans/action_stubs/upload_stub.rb
bolt-1.29.1 lib/bolt_spec/plans/action_stubs/upload_stub.rb
bolt-1.29.0 lib/bolt_spec/plans/action_stubs/upload_stub.rb
bolt-1.28.0 lib/bolt_spec/plans/action_stubs/upload_stub.rb
bolt-1.27.1 lib/bolt_spec/plans/action_stubs/upload_stub.rb
bolt-1.27.0 lib/bolt_spec/plans/action_stubs/upload_stub.rb
bolt-1.26.0 lib/bolt_spec/plans/action_stubs/upload_stub.rb
bolt-1.25.0 lib/bolt_spec/plans/action_stubs/upload_stub.rb
bolt-1.24.0 lib/bolt_spec/plans/action_stubs/upload_stub.rb
bolt-1.23.0 lib/bolt_spec/plans/action_stubs/upload_stub.rb
bolt-1.22.0 lib/bolt_spec/plans/action_stubs/upload_stub.rb
bolt-1.21.0 lib/bolt_spec/plans/action_stubs/upload_stub.rb
bolt-1.20.0 lib/bolt_spec/plans/action_stubs/upload_stub.rb
bolt-1.19.0 lib/bolt_spec/plans/action_stubs/upload_stub.rb
bolt-1.18.0 lib/bolt_spec/plans/action_stubs/upload_stub.rb
bolt-1.17.0 lib/bolt_spec/plans/action_stubs/upload_stub.rb