Class: BoltSpec::Plans::PlanStub

Inherits:
ActionStub show all
Defined in:
lib/bolt_spec/plans/action_stubs/plan_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, #expect_call, #initialize, #not_be_called, #return, #with_targets

Constructor Details

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

Instance Method Details

#call(_scope, plan, params) ⇒ Object



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

def call(_scope, plan, params)
  @calls += 1
  if @return_block
    check_plan_result(@return_block.call(plan: plan, params: params), plan)
  else
    default_for(nil)
  end
end

#error_with(data, clazz = Bolt::PlanFailure) ⇒ Object



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

def error_with(data, clazz = Bolt::PlanFailure)
  super(data, clazz)
end

#matches(_scope, _plan, params) ⇒ Object



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

def matches(_scope, _plan, params)
  targets = params.fetch('nodes', params.fetch('targets', nil))
  if @invocation[:targets] && Set.new(@invocation[:targets]) != Set.new(targets)
    return false
  end

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

  true
end

#parametersObject



28
29
30
# File 'lib/bolt_spec/plans/action_stubs/plan_stub.rb', line 28

def parameters
  @invocation[:params]
end

#result_for(_target, data) ⇒ Object

Allow any data.



33
34
35
# File 'lib/bolt_spec/plans/action_stubs/plan_stub.rb', line 33

def result_for(_target, data)
  Bolt::PlanResult.new(Bolt::Util.walk_keys(data, &:to_s), 'success')
end

#return_for_targets(_data) ⇒ Object



46
47
48
# File 'lib/bolt_spec/plans/action_stubs/plan_stub.rb', line 46

def return_for_targets(_data)
  raise "return_for_targets is not implemented for plan spec tests (allow_plan, expect_plan, allow_any_plan, etc)"
end

#with_params(params) ⇒ Object

Restricts the stub to only match invocations with certain parameters. All parameters must match exactly.



41
42
43
44
# File 'lib/bolt_spec/plans/action_stubs/plan_stub.rb', line 41

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