Skip to content
This repository was archived by the owner on Nov 30, 2024. It is now read-only.

Assign @metadata before we apply derived metadata hooks. #2635

Merged
merged 1 commit into from
Jun 21, 2019

Conversation

myronmarston
Copy link
Member

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.

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)
Copy link
Member

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.

Copy link
Member Author

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 :).

@myronmarston
Copy link
Member Author

@JonRowe anything you'd like to see before this gets merged?

Copy link
Member

@benoittgt benoittgt left a 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.

@myronmarston myronmarston merged commit 2a62a64 into master Jun 21, 2019
@myronmarston myronmarston deleted the myron/fix-shared-context-metadata-bug branch June 21, 2019 14:31
@myronmarston
Copy link
Member Author

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 :).

@benoittgt
Copy link
Member

benoittgt commented Jun 22, 2019 via email

@JonRowe
Copy link
Member

JonRowe commented Jun 22, 2019

As a bugfix this should be back ported, and I'm happy for it to be released. We also need a change log entry for it I believe? (edit no, it just got mangled) Happy to take care of releasing or happy for you to take care of it @myronmarston :)

@myronmarston
Copy link
Member Author

Happy to take care of releasing

I'll gladly let you take care of it :).

JonRowe pushed a commit that referenced this pull request Jun 29, 2019
…-bug

Assign `@metadata` before we apply derived metadata hooks.
MatheusRich pushed a commit to MatheusRich/rspec-core that referenced this pull request Oct 30, 2020
…adata-bug

Assign `@metadata` before we apply derived metadata hooks.
yujinakayama pushed a commit to yujinakayama/rspec-monorepo that referenced this pull request Oct 6, 2021
…shared-context-metadata-bug

Assign `@metadata` before we apply derived metadata hooks.

---
This commit was imported from rspec/rspec-core@10a6942.
yujinakayama pushed a commit to yujinakayama/rspec-monorepo that referenced this pull request Oct 6, 2021
…shared-context-metadata-bug

Assign `@metadata` before we apply derived metadata hooks.

---
This commit was imported from rspec/rspec-core@2a62a64.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants