Class: BoltSpec::Plans::DownloadStub

Inherits:
ActionStub show all
Defined in:
lib/bolt_spec/plans/action_stubs/download_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



50
51
52
# File 'lib/bolt_spec/plans/action_stubs/download_stub.rb', line 50

def always_return(_data)
  raise 'Download 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
38
# File 'lib/bolt_spec/plans/action_stubs/download_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
        download = File.join(destination, Bolt::Util.windows_basename(source))
        Bolt::Result.for_download(target, source, destination, download)
      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/download_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



40
41
42
# File 'lib/bolt_spec/plans/action_stubs/download_stub.rb', line 40

def parameters
  @invocation[:options]
end

#result_for(_target, _data) ⇒ Object



44
45
46
# File 'lib/bolt_spec/plans/action_stubs/download_stub.rb', line 44

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

#with_destination(destination) ⇒ Object



54
55
56
57
# File 'lib/bolt_spec/plans/action_stubs/download_stub.rb', line 54

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

#with_params(params) ⇒ Object



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

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