class RSpec::Core::LegacyExampleGroupHash
@private Together with the example group metadata hash default block, provides backwards compatibility for the old ‘:example_group` key. In RSpec
2.x, the computed keys of a group’s metadata were exposed from a nested subhash keyed by ‘[:example_group]`, and then the parent group’s metadata was exposed by sub-subhash keyed by ‘[:example_group]`.
In RSpec
3, we reorganized this to that the computed keys are exposed directly of the group metadata hash (no nesting), and ‘:parent_example_group` returns the parent group’s metadata.
Maintaining backwards compatibility was difficult: we wanted ‘:example_group` to return an object that:
* Exposes the top-level metadata keys that used to be nested under `:example_group`. * Supports mutation (rspec-rails, for example, assigns `metadata[:example_group][:described_class]` when you use anonymous controller specs) such that changes are written back to the top-level metadata hash. * Exposes the parent group metadata as `[:example_group][:example_group]`.
Public Class Methods
# File rspec-core/lib/rspec/core/metadata.rb, line 473 def initialize(metadata) @metadata = metadata parent_group_metadata = metadata.fetch(:parent_example_group) { {} }[:example_group] self[:example_group] = parent_group_metadata if parent_group_metadata end
Public Instance Methods
Calls superclass method
RSpec::Core::HashImitatable#to_h
# File rspec-core/lib/rspec/core/metadata.rb, line 479 def to_h super.merge(@metadata) end