Module: MiniTest::Chef::Resources

Includes:
Chef::Mixin::ConvertToClassName
Included in:
Spec, TestCase
Defined in:
lib/minitest-chef-handler/resources.rb

Class Method Summary collapse

Class Method Details

.register_resource(resource, *required_args) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/minitest-chef-handler/resources.rb', line 10

def self.register_resource(resource, *required_args)
  define_method(resource) do |name, *options|
    clazz = ::Chef::Resource.const_get(convert_to_class_name(resource.to_s))
    res = clazz.new(name, run_context)
    required_args.each do |arg|
      res.send(arg, options.first[arg])
    end

    # in Chef 10.14.0 an additional argument was added to Chef::Platform.provider_for_resource
    # so we check the version here and use it if it is available
    if Gem::Version.new(::Chef::VERSION) < Gem::Version.new("10.14.0")
      provider = ::Chef::Platform.provider_for_resource(res)
    else
      provider = ::Chef::Platform.provider_for_resource(res, :create)
    end

    provider.load_current_resource
    provider.current_resource
  end
end