module RSpec::Core::MetadataFilter
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.
Public Class Methods
apply?(predicate, filters, metadata)
click to toggle source
@private
# File lib/rspec/core/metadata_filter.rb, line 11 def apply?(predicate, filters, metadata) filters.__send__(predicate) { |k, v| filter_applies?(k, v, metadata) } end
filter_applies?(key, value, metadata)
click to toggle source
@private
# File lib/rspec/core/metadata_filter.rb, line 16 def filter_applies?(key, value, metadata) silence_metadata_example_group_deprecations do return location_filter_applies?(value, metadata) if key == :locations return id_filter_applies?(value, metadata) if key == :ids return filters_apply?(key, value, metadata) if Hash === value return false unless metadata.key?(key) return true if TrueClass === value && !!metadata[key] return filter_applies_to_any_value?(key, value, metadata) if Array === metadata[key] && !(Proc === value) case value when Regexp metadata[key] =~ value when Proc proc_filter_applies?(key, value, metadata) else metadata[key].to_s == value.to_s end end end
Private Class Methods
filter_applies_to_any_value?(key, value, metadata)
click to toggle source
# File lib/rspec/core/metadata_filter.rb, line 39 def filter_applies_to_any_value?(key, value, metadata) metadata[key].any? { |v| filter_applies?(key, v, key => value) } end
filters_apply?(key, value, metadata)
click to toggle source
# File lib/rspec/core/metadata_filter.rb, line 70 def filters_apply?(key, value, metadata) subhash = metadata[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)
click to toggle source
# File lib/rspec/core/metadata_filter.rb, line 43 def id_filter_applies?(rerun_paths_to_scoped_ids, metadata) scoped_ids = rerun_paths_to_scoped_ids.fetch(metadata[:rerun_file_path]) { return false } Metadata.ascend(metadata).any? do |meta| scoped_ids.include?(meta[:scoped_id]) end end
location_filter_applies?(locations, metadata)
click to toggle source
# File lib/rspec/core/metadata_filter.rb, line 51 def location_filter_applies?(locations, metadata) Metadata.ascend(metadata).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)
click to toggle source
# File lib/rspec/core/metadata_filter.rb, line 62 def proc_filter_applies?(key, proc, metadata) case proc.arity when 0 then proc.call when 2 then proc.call(metadata[key], metadata) else proc.call(metadata[key]) end end
silence_metadata_example_group_deprecations() { || ... }
click to toggle source
# File lib/rspec/core/metadata_filter.rb, line 76 def silence_metadata_example_group_deprecations RSpec::Support.thread_local_data[:silence_metadata_example_group_deprecations] = true yield ensure RSpec::Support.thread_local_data.delete(:silence_metadata_example_group_deprecations) end