Module: BoltSpec::BoltContext

Included in:
Plans
Defined in:
lib/bolt_spec/bolt_context.rb

Instance Method Summary collapse

Instance Method Details

#allow_out_messageObject Also known as: allow_any_out_message

Does this belong here?



187
188
189
# File 'lib/bolt_spec/bolt_context.rb', line 187

def allow_out_message
  executor.stub_out_message.add_stub
end

#allow_out_verboseObject Also known as: allow_any_out_verbose



196
197
198
# File 'lib/bolt_spec/bolt_context.rb', line 196

def allow_out_verbose
  executor.stub_out_verbose.add_stub
end

#configObject

Override in your tests



150
151
152
153
154
155
156
# File 'lib/bolt_spec/bolt_context.rb', line 150

def config
  @config ||= begin
    conf = Bolt::Config.new(Bolt::Project.default_project, config_data)
    conf.modulepath = [modulepath].flatten
    conf
  end
end

#config_dataObject

Overrides configuration for tests.



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

def config_data
  {}
end

#executorObject



131
132
133
# File 'lib/bolt_spec/bolt_context.rb', line 131

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

#expect_out_messageObject



192
193
194
# File 'lib/bolt_spec/bolt_context.rb', line 192

def expect_out_message
  allow_out_message.expect_call
end

#expect_out_verboseObject



201
202
203
# File 'lib/bolt_spec/bolt_context.rb', line 201

def expect_out_verbose
  allow_out_verbose.expect_call
end

#in_bolt_context(&block) ⇒ Object



103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/bolt_spec/bolt_context.rb', line 103

def in_bolt_context(&block)
  setup
  old_modpath = RSpec.configuration.module_path
  old_tasks = Puppet[:tasks]

  # Set the things
  Puppet[:tasks] = true
  RSpec.configuration.module_path = [modulepath, Bolt::Config::Modulepath::BOLTLIB_PATH].join(File::PATH_SEPARATOR)
  opts = {
    bolt_executor: executor,
    bolt_inventory: inventory,
    bolt_pdb_client: nil,
    apply_executor: nil
  }
  Puppet.override(opts, &block)

  # Unset the things
  RSpec.configuration.module_path = old_modpath
  Puppet[:tasks] = old_tasks
end

#inventoryObject



145
146
147
# File 'lib/bolt_spec/bolt_context.rb', line 145

def inventory
  @inventory ||= Bolt::Inventory.create_version(inventory_data, config.transport, config.transports, plugins)
end

#inventory_dataObject

Overrides inventory for tests.



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

def inventory_data
  {}
end

#modulepathObject

Override in your tests if needed



125
126
127
128
129
# File 'lib/bolt_spec/bolt_context.rb', line 125

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

#palObject



162
163
164
165
166
# File 'lib/bolt_spec/bolt_context.rb', line 162

def pal
  @pal ||= Bolt::PAL.new(Bolt::Config::Modulepath.new(config.modulepath),
                         config.hiera_config,
                         config.project.resource_types)
end

#pluginsObject



158
159
160
# File 'lib/bolt_spec/bolt_context.rb', line 158

def plugins
  @plugins ||= Bolt::Plugin.new(config, pal)
end

#setupObject



95
96
97
98
99
100
101
# File 'lib/bolt_spec/bolt_context.rb', line 95

def setup
  unless @loaded
    # This is slow so don't do it until we have to
    Bolt::PAL.load_puppet
    @loaded = true
  end
end