-
-
Notifications
You must be signed in to change notification settings - Fork 753
Assign @metadata
before we apply derived metadata hooks.
#2635
Conversation
Since derived metadata hooks can contain arbitrary user code, the logic in them can trigger something that tries to access and use `Example#metadata` or `ExampleGroup#metadata` before initialization is done. It avoids problems if we allow `@metadata` to be assigned before we run the hooks.
@@ -424,11 +424,15 @@ def self.set_it_up(description, args, registration_collection, &example_group_bl | |||
superclass.method(:next_runnable_index_for), | |||
description, *args, &example_group_block | |||
) | |||
|
|||
config = RSpec.configuration | |||
config.apply_derived_metadata_to(@metadata) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a way to deduplicate this somehow? Could we roll it into RSpec.configuration
with a bit of memoization or is there a chicken and egg problem.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see how. We've already rolled the logic into RSpec.configuration
(in the form of RSpec.configuration.apply_derived_metadata_to(@metadata)
), but we need to call it from somewhere after @metadata
has been assigned.
You're welcome to give it a try in a follow up PR :).
@JonRowe anything you'd like to see before this gets merged? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch. I am ok with your patch.
Thanks @benoittgt! Thoughts from @rspec/rspec folks on backporting this to 3-8-maintenance and releasing 3.8.2 with this? I can take care off that if folks are up for it. I've got a project at work that could benefit from this :). |
I am ok for a new release
|
As a bugfix this should be back ported, and I'm happy for it to be released. |
I'll gladly let you take care of it :). |
…-bug Assign `@metadata` before we apply derived metadata hooks.
…adata-bug Assign `@metadata` before we apply derived metadata hooks.
…shared-context-metadata-bug Assign `@metadata` before we apply derived metadata hooks. --- This commit was imported from rspec/rspec-core@10a6942.
…shared-context-metadata-bug Assign `@metadata` before we apply derived metadata hooks. --- This commit was imported from rspec/rspec-core@2a62a64.
Since derived metadata hooks can contain arbitrary user code,
the logic in them can trigger something that tries to access
and use
Example#metadata
orExampleGroup#metadata
beforeinitialization is done. It avoids problems if we allow
@metadata
to be assigned before we run the hooks.