Class: BoltSpec::Plans::CommandStub

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

Instance Attribute Summary

Attributes inherited from ActionStub

#invocation

Instance Method Summary collapse

Methods inherited from ActionStub

#always_return, #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

#call(targets, command, options) ⇒ Object



18
19
20
21
22
23
24
25
# File 'lib/bolt_spec/plans/action_stubs/command_stub.rb', line 18

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

#matches(targets, _command, options) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/bolt_spec/plans/action_stubs/command_stub.rb', line 6

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

#parametersObject



27
28
29
# File 'lib/bolt_spec/plans/action_stubs/command_stub.rb', line 27

def parameters
  @invocation[:options]
end

#result_for(target, stdout: '', stderr: '') ⇒ Object



31
32
33
# File 'lib/bolt_spec/plans/action_stubs/command_stub.rb', line 31

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

#with_params(params) ⇒ Object

Public methods



37
38
39
40
41
# File 'lib/bolt_spec/plans/action_stubs/command_stub.rb', line 37

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