Module: RSpec::Core::MetadataFilter

Defined in:
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 collapse

Class Method Details

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

Returns:

  • (Boolean)


11
12
13
# File '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

Returns:

  • (Boolean)


16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File '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

.silence_metadata_example_group_deprecationsObject



33
34
35
36
37
38
# File 'lib/rspec/core/metadata_filter.rb', line 33

def 
  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