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
- .apply?(predicate, filters, metadata) ⇒ Boolean Internal use only Internal use only
- .filter_applies?(key, filter_value, metadata) ⇒ Boolean Internal use only Internal use only
- .silence_metadata_example_group_deprecations Internal use only Internal use only
- .filter_applies_to_any_value?(key, value, metadata) ⇒ Boolean private
- .filters_apply?(key, value, metadata) ⇒ Boolean private
- .id_filter_applies?(rerun_paths_to_scoped_ids, metadata) ⇒ Boolean private
- .location_filter_applies?(locations, metadata) ⇒ Boolean private
- .proc_filter_applies?(key, proc, metadata) ⇒ Boolean private
Class Method Details
.apply?(predicate, filters, metadata) ⇒ Boolean
This method is for internal use only.
# 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.
# 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 = .fetch(key) { return false } return true if TrueClass === filter_value && return proc_filter_applies?(key, filter_value, ) if Proc === filter_value return filter_applies_to_any_value?(key, filter_value, ) if Array === filter_value === || filter_value.to_s == .to_s end end
.filter_applies_to_any_value?(key, value, metadata) ⇒ Boolean
(private)
# 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)
# 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)
.location_filter_applies?(locations, metadata) ⇒ Boolean
(private)
# File 'rspec-core/lib/rspec/core/metadata_filter.rb', line 54
def location_filter_applies?(locations, ) Metadata.ascend( ).any? do || file_path = [:absolute_file_path] line_num = [: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)
# 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