123456789_123456789_123456789_123456789_123456789_

Module: RSpec::Core::MetadataFilter

Relationships & Source Files
Defined in: rspec-core/lib/rspec/core/metadata_filter.rb

Overview

Contains metadata filtering logic. This has been extracted from the metadata classes because it operates ON a metadata hash but does not manage any of the state in the hash. We’re moving towards having metadata be a raw hash (not a custom subclass), so externalizing this filtering logic helps us move in that direction.

Class Method Summary

Class Method Details

.apply?(predicate, filters, metadata) ⇒ Boolean

This method is for internal use only.
[ GitHub ]

  
# File 'rspec-core/lib/rspec/core/metadata_filter.rb', line 11

def apply?(predicate, filters, )
  filters.__send__(predicate) { |k, v| filter_applies?(k, v, ) }
end

.filter_applies?(key, filter_value, metadata) ⇒ Boolean

This method is for internal use only.
[ GitHub ]

  
# File 'rspec-core/lib/rspec/core/metadata_filter.rb', line 16

def filter_applies?(key, filter_value, )
   do
    return location_filter_applies?(filter_value, ) if key == :locations
    return id_filter_applies?(filter_value, )       if key == :ids
    return filters_apply?(key, filter_value, )      if Hash === filter_value

    meta_value = .fetch(key) { return false }

    return true if TrueClass === filter_value && meta_value
    return proc_filter_applies?(key, filter_value, ) if Proc === filter_value
    return filter_applies_to_any_value?(key, filter_value, ) if Array === meta_value

    filter_value === meta_value || filter_value.to_s == meta_value.to_s
  end
end

.filter_applies_to_any_value?(key, value, metadata) ⇒ Boolean (private)

[ GitHub ]

  
# File 'rspec-core/lib/rspec/core/metadata_filter.rb', line 42

def filter_applies_to_any_value?(key, value, )
  [key].any? { |v| filter_applies?(key, v,  key => value) }
end

.filters_apply?(key, value, metadata) ⇒ Boolean (private)

[ GitHub ]

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

def filters_apply?(key, value, )
  subhash = [key]
  return false unless Hash === subhash || HashImitatable === subhash
  value.all? { |k, v| filter_applies?(k, v, subhash) }
end

.id_filter_applies?(rerun_paths_to_scoped_ids, metadata) ⇒ Boolean (private)

[ GitHub ]

  
# File 'rspec-core/lib/rspec/core/metadata_filter.rb', line 46

def id_filter_applies?(rerun_paths_to_scoped_ids, )
  scoped_ids = rerun_paths_to_scoped_ids.fetch([:rerun_file_path]) { return false }

  Metadata.ascend().any? do |meta|
    scoped_ids.include?(meta[:scoped_id])
  end
end

.location_filter_applies?(locations, metadata) ⇒ Boolean (private)

[ GitHub ]

  
# File 'rspec-core/lib/rspec/core/metadata_filter.rb', line 54

def location_filter_applies?(locations, )
  Metadata.ascend().any? do |meta|
    file_path = meta[:absolute_file_path]
    line_num  = meta[:line_number]

    locations[file_path].any? do |filter_line_num|
      line_num == RSpec.world.preceding_declaration_line(file_path, filter_line_num)
    end
  end
end

.proc_filter_applies?(key, proc, metadata) ⇒ Boolean (private)

[ GitHub ]

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

def proc_filter_applies?(key, proc, )
  case proc.arity
  when 0 then proc.call
  when 2 then proc.call([key], )
  else proc.call([key])
  end
end

.silence_metadata_example_group_deprecations

This method is for internal use only.
[ GitHub ]

  
# File 'rspec-core/lib/rspec/core/metadata_filter.rb', line 33

def 
  RSpec::Support.thread_local_data[:] = true
  yield
ensure
  RSpec::Support.thread_local_data.delete(:)
end