123456789_123456789_123456789_123456789_123456789_

Class: RSpec::Core::FilterManager Private

Do not use. This class is for internal use only.
Relationships & Source Files
Inherits: Object
Defined in: rspec-core/lib/rspec/core/filter_manager.rb

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Instance Attribute Details

#empty?Boolean (readonly)

[ GitHub ]

  
# File 'rspec-core/lib/rspec/core/filter_manager.rb', line 30

def empty?
  inclusions.empty? && exclusions.empty?
end

#exclusions (readonly)

[ GitHub ]

  
# File 'rspec-core/lib/rspec/core/filter_manager.rb', line 5

attr_reader :exclusions, :inclusions

#inclusions (readonly)

[ GitHub ]

  
# File 'rspec-core/lib/rspec/core/filter_manager.rb', line 5

attr_reader :exclusions, :inclusions

Instance Method Details

#add_ids(rerun_path, scoped_ids)

[ GitHub ]

  
# File 'rspec-core/lib/rspec/core/filter_manager.rb', line 22

def add_ids(rerun_path, scoped_ids)
  # ids is a hash of relative paths to arrays of ids
  # to match against. e.g.
  #   { "./path/to/file.rb" => ["1:1", "2:4"] }
  rerun_path = Metadata.relative_path(File.expand_path rerun_path)
  add_path_to_arrays_filter(:ids, rerun_path, scoped_ids)
end

#add_location(file_path, line_numbers)

Parameters:

  • file_path (String)
  • line_numbers (Array)
[ GitHub ]

  
# File 'rspec-core/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] }
  add_path_to_arrays_filter(:locations, File.expand_path(file_path), line_numbers)
end

#add_path_to_arrays_filter(filter_key, path, values) (private)

[ GitHub ]

  
# File 'rspec-core/lib/rspec/core/filter_manager.rb', line 83

def add_path_to_arrays_filter(filter_key, path, values)
  filter = inclusions.delete(filter_key) || Hash.new { |h, k| h[k] = [] }
  filter[path].concat(values)
  inclusions.add(filter_key => filter)
end

#exclude(*args)

[ GitHub ]

  
# File 'rspec-core/lib/rspec/core/filter_manager.rb', line 57

def exclude(*args)
  exclusions.add(args.last)
end

#exclude_only(*args)

[ GitHub ]

  
# File 'rspec-core/lib/rspec/core/filter_manager.rb', line 61

def exclude_only(*args)
  exclusions.use_only(args.last)
end

#exclude_with_low_priority(*args)

[ GitHub ]

  
# File 'rspec-core/lib/rspec/core/filter_manager.rb', line 65

def exclude_with_low_priority(*args)
  exclusions.add_with_low_priority(args.last)
end

#file_scoped_include?(ex_metadata, ids, locations) ⇒ Boolean (private)

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.

[ GitHub ]

  
# File 'rspec-core/lib/rspec/core/filter_manager.rb', line 101

def file_scoped_include?(, ids, locations)
  no_id_filters = ids[[:rerun_file_path]].empty?
  no_location_filters = locations[
    File.expand_path([:rerun_file_path])
  ].empty?

  return yield if no_location_filters && no_id_filters

  MetadataFilter.filter_applies?(:ids, ids, ) ||
  MetadataFilter.filter_applies?(:locations, locations, )
end

#include(*args)

[ GitHub ]

  
# File 'rspec-core/lib/rspec/core/filter_manager.rb', line 69

def include(*args)
  inclusions.add(args.last)
end

#include_only(*args)

[ GitHub ]

  
# File 'rspec-core/lib/rspec/core/filter_manager.rb', line 73

def include_only(*args)
  inclusions.use_only(args.last)
end

#include_with_low_priority(*args)

[ GitHub ]

  
# File 'rspec-core/lib/rspec/core/filter_manager.rb', line 77

def include_with_low_priority(*args)
  inclusions.add_with_low_priority(args.last)
end

#prune(examples)

[ GitHub ]

  
# File 'rspec-core/lib/rspec/core/filter_manager.rb', line 34

def prune(examples)
  # Semantically, this is unnecessary (the filtering below will return the empty
  # array unmodified), but for perf reasons it's worth exiting early here. Users
  # commonly have top-level examples groups that do not have any direct examples
  # and instead have nested groups with examples. In that kind of situation,
  # `examples` will be empty.
  return examples if examples.empty?

  examples = prune_conditionally_filtered_examples(examples)

  if inclusions.standalone?
    examples.select { |e| inclusions.include_example?(e) }
  else
    locations, ids, non_scoped_inclusions = inclusions.split_file_scoped_rules

    examples.select do |ex|
      file_scoped_include?(ex., ids, locations) do
        !exclusions.include_example?(ex) && non_scoped_inclusions.include_example?(ex)
      end
    end
  end
end

#prune_conditionally_filtered_examples(examples) (private)

[ GitHub ]

  
# File 'rspec-core/lib/rspec/core/filter_manager.rb', line 89

def prune_conditionally_filtered_examples(examples)
  examples.reject do |ex|
    meta = ex.
    !meta.fetch(:if, true) || meta[:unless]
  end
end