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


53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/chefspec/coverage/filters.rb', line 53

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


72
73
74
75
# File 'lib/chefspec/coverage/filters.rb', line 72

def matches?(resource)
  return true if resource.source_line.nil?
  resource.source_line =~ /cookbooks\/(?!#{@metadatas.join('|')})/
end