libraries/matchers.rb
# Instead of defining each matcher method, we're going to save some time by doing some meta programming
# To see a full list of the actual matchers, see spec/unit/resources/matchers_spec.rb
Instead of defining each matcher method, we're going to save some time by doing some meta programming
To see a full list of the actual matchers, see spec/unit/resources/matchers_spec.rb
Instead of defining each matcher method we ' re going to save some time by doing some meta programming To see a full list of the actual matchers see spec / unit / resources / matchers_spec . rb
def define_chefspec_matchers(resource_map, recognized_actions)
    resource_map.each do |resource_type, actions|
      actions.each do |action|
        description = action.to_s.split('_')
        action_indexes = recognized_actions.map { |action_word| description.rindex(action_word) }
        last_action_index = action_indexes.compact.max
        description.insert(last_action_index + 1, resource_type.to_s)
        method_name = description.join('_')
        define_method(method_name) do |resource_name|
          ChefSpec::Matchers::ResourceMatcher.new(resource_type, action, resource_name)
        end
      end
    end
  end
def define_chefspec_matchers ( resource_map , recognized_actions ) resource_map . each do | resource_type , actions | actions . each do | action | description = action . to_s . split ( '_' ) action_indexes = recognized_actions . map { | action_word | description . rindex ( action_word ) } last_action_index = action_indexes . compact . max description . insert ( last_action_index + 1 , resource_type . to_s ) method_name = description . join ( '_' ) define_method ( method_name ) do | resource_name | ChefSpec :: Matchers :: ResourceMatcher . new ( resource_type , action , resource_name ) end end end end
Instead of defining each matcher method, we're going to save some time by doing some meta programming
To see a full list of the actual matchers, see spec/unit/resources/matchers_spec.rb
Instead of defining each matcher method we ' re going to save some time by doing some meta programming To see a full list of the actual matchers see spec / unit / resources / matchers_spec . rb
# Each action should follow <action_clause>_<resource_type>[_<object_complement>] naming standards # Finds the last action cited in the action description # Inserts the resource type after the action # Rejoin everything
resource_map
recognized_actions