Module: ChefSpec::Normalize

Included in:
Matchers::NotificationsMatcher, Matchers::SubscribesMatcher, Renderer, SoloRunner
Defined in:
lib/chefspec/mixins/normalize.rb

Instance Method Summary collapse

Instance Method Details

#resource_name(thing) ⇒ Symbol

Calculate the name of a resource, replacing dashes with underscores and converting symbols to strings and back again.

Parameters:

  • thing (String, Chef::Resource)

Returns:

  • (Symbol)


11
12
13
14
15
16
17
18
19
20
# File 'lib/chefspec/mixins/normalize.rb', line 11

def resource_name(thing)
  if thing.respond_to?(:declared_type) && thing.declared_type
    name = thing.declared_type
  elsif thing.respond_to?(:resource_name)
    name = thing.resource_name
  else
    name = thing
  end
  name.to_s.gsub("-", "_").to_sym
end