class ChefSpec::Coverage::BerkshelfFilter

@example Ignore dependent cookbooks (via Berkshelf)

add_filter BerkshelfFilter.new(berksfile)

Public Class Methods

new(berksfile) click to toggle source
# File lib/chefspec/coverage/filters.rb, line 55
def initialize(berksfile)
  @berksfile = berksfile

  @metadatas = if berksfile.respond_to?(:dependencies)
                 berksfile.dependencies
                   .select(&:metadata?)
                   .map(&:name)
               else
                 berksfile.sources.collect do |source|
                   location = source.location
                   if location.respond_to?(:metadata?) && location.metadata?
                     source
                   else
                     nil
                   end
                 end.compact.map(&:name)
               end
end

Public Instance Methods

matches?(resource) click to toggle source
# File lib/chefspec/coverage/filters.rb, line 74
def matches?(resource)
  return true if resource.source_line.nil?

  normalized_source_line = resource.source_line.gsub("\\", "/")
  normalized_source_line =~ %r{cookbooks/(?!#{@metadatas.join('|')})}
end