class RSpec::Core::FilterManager

@private

Attributes

exclusions[R]
inclusions[R]

Public Class Methods

new() click to toggle source
# File lib/rspec/core/filter_manager.rb, line 7
def initialize
  @exclusions, @inclusions = FilterRules.build
end

Public Instance Methods

add_location(file_path, line_numbers) click to toggle source

@api private

@param file_path [String] @param line_numbers [Array]

# File lib/rspec/core/filter_manager.rb, line 15
def add_location(file_path, line_numbers)
  # locations is a hash of expanded paths to arrays of line
  # numbers to match against. e.g.
  #   { "path/to/file.rb" => [37, 42] }
  locations = inclusions.delete(:locations) || Hash.new { |h, k| h[k] = [] }
  locations[File.expand_path(file_path)].push(*line_numbers)
  inclusions.add(:locations => locations)
end
empty?() click to toggle source
# File lib/rspec/core/filter_manager.rb, line 24
def empty?
  inclusions.empty? && exclusions.empty?
end
exclude(*args) click to toggle source
# File lib/rspec/core/filter_manager.rb, line 44
def exclude(*args)
  exclusions.add(args.last)
end
exclude_only(*args) click to toggle source
# File lib/rspec/core/filter_manager.rb, line 48
def exclude_only(*args)
  exclusions.use_only(args.last)
end
exclude_with_low_priority(*args) click to toggle source
# File lib/rspec/core/filter_manager.rb, line 52
def exclude_with_low_priority(*args)
  exclusions.add_with_low_priority(args.last)
end
include(*args) click to toggle source
# File lib/rspec/core/filter_manager.rb, line 56
def include(*args)
  inclusions.add(args.last)
end
include_only(*args) click to toggle source
# File lib/rspec/core/filter_manager.rb, line 60
def include_only(*args)
  inclusions.use_only(args.last)
end
include_with_low_priority(*args) click to toggle source
# File lib/rspec/core/filter_manager.rb, line 64
def include_with_low_priority(*args)
  inclusions.add_with_low_priority(args.last)
end
prune(examples) click to toggle source
# File lib/rspec/core/filter_manager.rb, line 28
def prune(examples)
  examples = prune_conditionally_filtered_examples(examples)

  if inclusions.standalone?
    examples.select { |e| include?(e) }
  else
    locations, other_inclusions = inclusions.partition_locations

    examples.select do |e|
      priority_include?(e, locations) do
        !exclude?(e) && other_inclusions.include_example?(e)
      end
    end
  end
end

Private Instance Methods

exclude?(example) click to toggle source
# File lib/rspec/core/filter_manager.rb, line 70
def exclude?(example)
  exclusions.include_example?(example)
end
include?(example) click to toggle source
# File lib/rspec/core/filter_manager.rb, line 74
def include?(example)
  inclusions.include_example?(example)
end
priority_include?(example, locations) { || ... } click to toggle source

When a user specifies a particular spec location, that takes priority over any exclusion filters (such as if the spec is tagged with `:slow` and there is a `:slow => true` exclusion filter), but only for specs defined in the same file as the location filters. Excluded specs in other files should still be excluded.

# File lib/rspec/core/filter_manager.rb, line 90
def priority_include?(example, locations)
  return yield if locations[example.metadata[:absolute_file_path]].empty?
  MetadataFilter.filter_applies?(:locations, locations, example.metadata)
end
prune_conditionally_filtered_examples(examples) click to toggle source
# File lib/rspec/core/filter_manager.rb, line 78
def prune_conditionally_filtered_examples(examples)
  examples.reject do |ex|
    meta = ex.metadata
    !meta.fetch(:if, true) || meta[:unless]
  end
end