Skip to content

Fix adding config hooks to existing example groups

Created by: eugeneius

Followup to https://github.com/rspec/rspec-core/pull/2189.

When an example group is created, the existing config hooks are added to it if their metadata filters match and none of the new example group's parent groups already have the hook added.

The current implementation adds new config hooks to all existing example groups, which means they can be run multiple times if several nested example groups all match their metadata filters, which doesn't happen if the config hook is defined first.

To get the same behaviour regardless of the order in which hooks and groups are defined, we can walk the inheritance hierarchy starting from the top level example groups, and only add the new hook to the first matching group on each branch.

Merge request reports