Class: BoltSpec::Plans::ScriptStub
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
Instance Method Details
#call(targets, script, arguments, options) ⇒ Object
22
23
24
25
26
27
28
29
30
31
|
# File 'lib/bolt_spec/plans/action_stubs/script_stub.rb', line 22
def call(targets, script, arguments, options)
@calls += 1
if @return_block
params = options.merge('arguments' => arguments)
check_resultset(@return_block.call(targets: targets, script: script, params: params), script)
else
Bolt::ResultSet.new(targets.map { |target| @data[target.name] || default_for(target) })
end
end
|
#matches(targets, _script, arguments, options) ⇒ Object
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
# File 'lib/bolt_spec/plans/action_stubs/script_stub.rb', line 6
def matches(targets, _script, arguments, options)
if @invocation[:targets] && Set.new(@invocation[:targets]) != Set.new(targets.map(&:name))
return false
end
if @invocation[:arguments] && arguments != @invocation[:arguments]
return false
end
if @invocation[:options] && options != @invocation[:options]
return false
end
true
end
|
#parameters ⇒ Object
33
34
35
|
# File 'lib/bolt_spec/plans/action_stubs/script_stub.rb', line 33
def parameters
@invocation[:params]
end
|
#result_for(target, stdout: '', stderr: '') ⇒ Object
37
38
39
40
41
42
43
44
45
46
|
# File 'lib/bolt_spec/plans/action_stubs/script_stub.rb', line 37
def result_for(target, stdout: '', stderr: '')
value = {
'stdout' => stdout,
'stderr' => stderr,
'merged_output' => "#{stdout}\n#{stderr}".strip,
'exit_code' => 0
}
Bolt::Result.for_command(target, value, 'script', '', [])
end
|
#with_params(params) ⇒ Object
50
51
52
53
54
55
56
|
# File 'lib/bolt_spec/plans/action_stubs/script_stub.rb', line 50
def with_params(params)
@invocation[:params] = params
@invocation[:arguments] = params['arguments']
@invocation[:options] = params.select { |k, _v| k.start_with?('_') }
.transform_keys { |k| k.sub(/^_/, '').to_sym }
self
end
|