Class: ChefSpec::Coverage::BerkshelfFilter

Inherits:
Filter
  • Object
show all
Defined in:
lib/chefspec/coverage/filters.rb

Overview

Examples:

Ignore dependent cookbooks (via Berkshelf)

add_filter BerkshelfFilter.new(berksfile)

Instance Method Summary collapse

Constructor Details

#initialize(berksfile) ⇒ BerkshelfFilter

Returns a new instance of BerkshelfFilter.



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# 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

Instance Method Details

#matches?(resource) ⇒ Boolean

Returns:

  • (Boolean)


74
75
76
77
78
79
# 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