Class: BoltSpec::Plans::UploadStub

Inherits:
ActionStub show all
Defined in:
lib/bolt_spec/plans/action_stubs/upload_stub.rb

Instance Attribute Summary

Attributes inherited from ActionStub

#invocation

Instance Method Summary collapse

Methods inherited from ActionStub

#assert_called, #be_called_times, #check_plan_result, #check_resultset, #default_for, #error_with, #expect_call, #initialize, #not_be_called, #return, #return_for_targets, #with_targets

Constructor Details

This class inherits a constructor from BoltSpec::Plans::ActionStub

Instance Method Details

#always_return(_data) ⇒ Object

Public methods



49
50
51
# File 'lib/bolt_spec/plans/action_stubs/upload_stub.rb', line 49

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

#call(targets, source, destination, options) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/bolt_spec/plans/action_stubs/upload_stub.rb', line 22

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

#matches(targets, _source, destination, options) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/bolt_spec/plans/action_stubs/upload_stub.rb', line 6

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

#parametersObject



39
40
41
# File 'lib/bolt_spec/plans/action_stubs/upload_stub.rb', line 39

def parameters
  @invocation[:options]
end

#result_for(_target, _data) ⇒ Object



43
44
45
# File 'lib/bolt_spec/plans/action_stubs/upload_stub.rb', line 43

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

#with_destination(destination) ⇒ Object



53
54
55
56
# File 'lib/bolt_spec/plans/action_stubs/upload_stub.rb', line 53

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

#with_params(params) ⇒ Object



58
59
60
61
62
# File 'lib/bolt_spec/plans/action_stubs/upload_stub.rb', line 58

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