@@ -34,6 +34,14 @@ def filter_applies?(key, value, metadata)
34
34
end
35
35
end
36
36
37
+ # @private
38
+ def silence_metadata_example_group_deprecations
39
+ RSpec ::Support . thread_local_data [ :silence_metadata_example_group_deprecations ] = true
40
+ yield
41
+ ensure
42
+ RSpec ::Support . thread_local_data . delete ( :silence_metadata_example_group_deprecations )
43
+ end
44
+
37
45
private
38
46
39
47
def filter_applies_to_any_value? ( key , value , metadata )
@@ -72,13 +80,6 @@ def filters_apply?(key, value, metadata)
72
80
return false unless Hash === subhash || HashImitatable === subhash
73
81
value . all? { |k , v | filter_applies? ( k , v , subhash ) }
74
82
end
75
-
76
- def silence_metadata_example_group_deprecations
77
- RSpec ::Support . thread_local_data [ :silence_metadata_example_group_deprecations ] = true
78
- yield
79
- ensure
80
- RSpec ::Support . thread_local_data . delete ( :silence_metadata_example_group_deprecations )
81
- end
82
83
end
83
84
end
84
85
@@ -202,9 +203,20 @@ def handle_mutation(metadata)
202
203
end
203
204
204
205
def applicable_metadata_from ( metadata )
205
- @applicable_keys . inject ( { } ) do |hash , key |
206
- hash [ key ] = metadata [ key ] if metadata . key? ( key )
207
- hash
206
+ MetadataFilter . silence_metadata_example_group_deprecations do
207
+ @applicable_keys . inject ( { } ) do |hash , key |
208
+ # :example_group is treated special here because...
209
+ # - In RSpec 2, example groups had an `:example_group` key
210
+ # - In RSpec 3, that key is deprecated (it was confusing!).
211
+ # - The key is not technically present in an example group metadata hash
212
+ # (and thus would fail the `metadata.key?(key)` check) but a value
213
+ # is provided when accessed via the hash's `default_proc`
214
+ # - Thus, for backwards compatibility, we have to explicitly check
215
+ # for `:example_group` here if it is one of the keys being used to
216
+ # filter.
217
+ hash [ key ] = metadata [ key ] if metadata . key? ( key ) || key == :example_group
218
+ hash
219
+ end
208
220
end
209
221
end
210
222
0 commit comments