Module: BoltSpec::Plans

Defined in:
lib/bolt_spec/plans.rb,
lib/bolt_spec/plans/mock_executor.rb

Defined Under Namespace

Classes: MockExecutor, TaskDouble, TaskStub, UnexpectedInvocation

Instance Method Summary collapse

Instance Method Details

#allow_any_taskObject

This stub will catch any task call if there are no stubs specifically for that task



141
142
143
# File 'lib/bolt_spec/plans.rb', line 141

def allow_any_task
  executor.stub_task(:default).add_stub
end

#allow_task(task_name) ⇒ Object

Allowed task stubs can be called up to be_called_times number of times



130
131
132
# File 'lib/bolt_spec/plans.rb', line 130

def allow_task(task_name)
  executor.stub_task(task_name).add_stub
end

#configObject

Override in your tests



100
101
102
103
104
# File 'lib/bolt_spec/plans.rb', line 100

def config
  config = Bolt::Config.new(Bolt::Boltdir.new('.'), {})
  config.modulepath = modulepath
  config
end

#executorObject

intended to be private below here



170
171
172
# File 'lib/bolt_spec/plans.rb', line 170

def executor
  @executor ||= BoltSpec::Plans::MockExecutor.new
end

#expect_task(task_name) ⇒ Object

Expected task stubs must be called exactly the expected number of times or at least once without be_called_times



136
137
138
# File 'lib/bolt_spec/plans.rb', line 136

def expect_task(task_name)
  allow_task(task_name).expect_call
end

#inventoryObject

Override in your tests



107
108
109
# File 'lib/bolt_spec/plans.rb', line 107

def inventory
  @inventory ||= Bolt::Inventory.new({})
end

#modulepathObject

Override in your tests if needed



93
94
95
96
97
# File 'lib/bolt_spec/plans.rb', line 93

def modulepath
  [RSpec.configuration.module_path]
rescue NoMethodError
  raise "RSpec.configuration.module_path not defined set up rspec puppet or define modulepath for this test"
end

#puppetdb_clientObject



111
112
113
# File 'lib/bolt_spec/plans.rb', line 111

def puppetdb_client
  @puppetdb_client ||= mock('puppetdb_client')
end

#run_plan(name, params) ⇒ Object



115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/bolt_spec/plans.rb', line 115

def run_plan(name, params)
  pal = Bolt::PAL.new(config.modulepath, config.hiera_config)
  result = pal.run_plan(name, params, executor, inventory, puppetdb_client)

  if executor.error_message
    raise executor.error_message
  end

  executor.assert_call_expectations

  result
end