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

Auto-included shared contexts are not subject to the same scoping rules that manually included ones are #1762

Closed
myronmarston opened this issue Nov 4, 2014 · 2 comments
Milestone

Comments

@myronmarston
Copy link
Member

Currently, when you define a shared example group with metadata, the implementation does this:

mod = Module.new
(class << mod; self; end).__send__(:define_method, :included) do |host|
  host.class_exec(&block)
end
RSpec.configuration.include mod, *metadata_args

It delegates to configuration.include in order to make the shared group auto-included in example groups that have matching metadata.

There's a discrepancy with the scoping rules of shared example groups, though: if the shared group is defined within a nested group it is only available for manual inclusion (using include_context or similar) within that group or a nested group. With the metadata auto-inclusion, the shared group would still be included in any matching example group, even if it's "out of scope" according to our manual inclusion scoping rules.

We should probably address this but maybe in the 4.0 timeframe?

/cc @JonRowe

@myronmarston myronmarston added this to the 4.0 milestone Nov 4, 2014
@JonRowe
Copy link
Member

JonRowe commented Nov 4, 2014

👍

@myronmarston
Copy link
Member Author

The change discussed in #1790 will solve this and I'm pretty sold on that, so I'm going to close this issue in favor of that one.

myronmarston added a commit that referenced this issue Jun 5, 2016
Previously, it always triggered auto-inclusion based on
matching metadata. The option allows you to opt-in to having
it add the metadata to included groups and examples instead.

- Closes #1790 (this is the last thing necessary for it).
- Addresses #1762.
- Addresses user confusion reported in:
  - rspec/rspec-rails#1241
  - rspec/rspec-rails#1579
myronmarston added a commit that referenced this issue Jun 5, 2016
Previously, it always triggered auto-inclusion based on
matching metadata. The option allows you to opt-in to having
it add the metadata to included groups and examples instead.

- Closes #1790 (this is the last thing necessary for it).
- Addresses #1762.
- Addresses user confusion reported in:
  - rspec/rspec-rails#1241
  - rspec/rspec-rails#1579
myronmarston added a commit that referenced this issue Jun 5, 2016
Previously, it always triggered auto-inclusion based on
matching metadata. The option allows you to opt-in to having
it add the metadata to included groups and examples instead.

- Closes #1790 (this is the last thing necessary for it).
- Addresses #1762.
- Addresses user confusion reported in:
  - rspec/rspec-rails#1241
  - rspec/rspec-rails#1579
myronmarston added a commit that referenced this issue Jun 5, 2016
Previously, it always triggered auto-inclusion based on
matching metadata. The option allows you to opt-in to having
it add the metadata to included groups and examples instead.

- Closes #1790 (this is the last thing necessary for it).
- Addresses #1762.
- Addresses user confusion reported in:
  - rspec/rspec-rails#1241
  - rspec/rspec-rails#1579
myronmarston added a commit that referenced this issue Jun 5, 2016
Previously, it always triggered auto-inclusion based on
matching metadata. The option allows you to opt-in to having
it add the metadata to included groups and examples instead.

- Closes #1790 (this is the last thing necessary for it).
- Addresses #1762.
- Addresses user confusion reported in:
  - rspec/rspec-rails#1241
  - rspec/rspec-rails#1579
myronmarston added a commit that referenced this issue Jun 5, 2016
Previously, it always triggered auto-inclusion based on
matching metadata. The option allows you to opt-in to having
it add the metadata to included groups and examples instead.

- Closes #1790 (this is the last thing necessary for it).
- Addresses #1762.
- Addresses user confusion reported in:
  - rspec/rspec-rails#1241
  - rspec/rspec-rails#1579
MatheusRich pushed a commit to MatheusRich/rspec-core that referenced this issue Oct 30, 2020
Previously, it always triggered auto-inclusion based on
matching metadata. The option allows you to opt-in to having
it add the metadata to included groups and examples instead.

- Closes rspec#1790 (this is the last thing necessary for it).
- Addresses rspec#1762.
- Addresses user confusion reported in:
  - rspec/rspec-rails#1241
  - rspec/rspec-rails#1579
pirj added a commit that referenced this issue Mar 1, 2021
yujinakayama pushed a commit to yujinakayama/rspec-monorepo that referenced this issue Oct 19, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants