Class: RSpec::Core::Metadata::ExampleGroupHash

Inherits:
HashPopulator show all
Defined in:
lib/rspec/core/metadata.rb

Instance Attribute Summary

Attributes inherited from HashPopulator

#block, #description_args, #metadata, #user_metadata

Class Method Summary collapse

Methods inherited from HashPopulator

#initialize, #populate

Constructor Details

This class inherits a constructor from RSpec::Core::Metadata::HashPopulator

Class Method Details

.backwards_compatibility_default_proc(&example_group_selector) ⇒ Object



266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
# File 'lib/rspec/core/metadata.rb', line 266

def self.backwards_compatibility_default_proc(&example_group_selector)
  Proc.new do |hash, key|
    case key
    when :example_group
      # We commonly get here when rspec-core is applying a previously
      # configured filter rule, such as when a gem configures:
      #
      #   RSpec.configure do |c|
      #     c.include MyGemHelpers, :example_group => { :file_path => /spec\/my_gem_specs/ }
      #   end
      #
      # It's confusing for a user to get a deprecation at this point in
      # the code, so instead we issue a deprecation from the config APIs
      # that take a metadata hash, and MetadataFilter sets this thread
      # local to silence the warning here since it would be so
      # confusing.
      unless RSpec::Support.thread_local_data[:silence_metadata_example_group_deprecations]
        RSpec.deprecate("The `:example_group` key in an example group's metadata hash",
                        :replacement => "the example group's hash directly for the " \
                        "computed keys and `:parent_example_group` to access the parent " \
                        "example group metadata")
      end

      group_hash = example_group_selector.call(hash)
      LegacyExampleGroupHash.new(group_hash) if group_hash
    when :example_group_block
      RSpec.deprecate("`metadata[:example_group_block]`",
                      :replacement => "`metadata[:block]`")
      hash[:block]
    when :describes
      RSpec.deprecate("`metadata[:describes]`",
                      :replacement => "`metadata[:described_class]`")
      hash[:described_class]
    end
  end
end

.create(parent_group_metadata, user_metadata, example_group_index, *args, &block) ⇒ Object



249
250
251
252
253
254
255
256
257
258
259
260
# File 'lib/rspec/core/metadata.rb', line 249

def self.create(, , example_group_index, *args, &block)
   = hash_with_backwards_compatibility_default_proc

  if 
    .update()
    [:parent_example_group] = 
  end

  hash = new(, , example_group_index, args, block)
  hash.populate
  hash.
end

.hash_with_backwards_compatibility_default_procObject



262
263
264
# File 'lib/rspec/core/metadata.rb', line 262

def self.hash_with_backwards_compatibility_default_proc
  Hash.new(&backwards_compatibility_default_proc { |hash| hash })
end