-
-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Run before(:all) hooks for rails magic example groups #829
Conversation
Thanks for tracking this down, @JonRowe. A few thoughts:
|
def set_metadata_type(type) | ||
metadata[:type] = type | ||
hooks.register_globals(self, RSpec.configuration.hooks) | ||
end |
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.
Looks like this isn't used anywhere? Looks like a useful abstraction, though; if we stick with this solution for some reason it would be good to leverage this. (Although I suspect the final fix will be in rspec-core).
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.
Oops yeah, I tried to DRY it up (couldn't get it to work cause of the included
scoping)
So do I, but this seemed the best way to start a discussion about it. The problem is that
I haven't tried, I don't remember us changing anything that would make it a regression, I will try at some point with 2.13.
I think this is a "sort of" bug in core, this is why I initially started poking at that to try to fix this. One way to solve this would be to make the metadata to reload global hooks when it's mutated. Or move the hook setup to be lazy and only configure from the global configuration when run (which is what your suggestion is I guess) |
Had to update this so it fails correctly, it's awaiting rspec/rspec-core#1089 before it'll work. |
Hi all-- What's the status on this PR and rspec/rspec-core#1089? Do we need it before 3.0? Can I help? |
So I'm still in favour of rspec/rspec-core#1089 but the alternative is we work something out that doesn't involve mutating metadata for rspec-rails integration |
- In #970 we added `infer_spec_type_from_file_location!` but forgot to remove the code in `lib/rspec/rails/configuration.rb` that made it always infer - so the opt-in API was there but it was always enabled. Here I've made it truly opt-in. - The logic of `infer_spec_type_from_file_location!` also setup the helper module inclusion via explicit `:type` metadata but was only intended to setup the implicit mapping of spec file location to type. Here I've made the module inclusion via `:type` always work w/o an explicit config option needed to enable it. - We used to mutate the `:type` metadata on inclusion of the helper module, but this caused bugs such as #825. The problem is that rspec-core uses a raw hash for the metadata and doesn't re-apply filtering/inclusion logic when the metadata hash is mutated. Instead, we use a new explicit `define_derived_metadata` API. Fixes #825 and closes #829.
Closing in favor of #1002. |
- In #970 we added `infer_spec_type_from_file_location!` but forgot to remove the code in `lib/rspec/rails/configuration.rb` that made it always infer - so the opt-in API was there but it was always enabled. Here I've made it truly opt-in. - The logic of `infer_spec_type_from_file_location!` also setup the helper module inclusion via explicit `:type` metadata but was only intended to setup the implicit mapping of spec file location to type. Here I've made the module inclusion via `:type` always work w/o an explicit config option needed to enable it. - We used to mutate the `:type` metadata on inclusion of the helper module, but this caused bugs such as #825. The problem is that rspec-core uses a raw hash for the metadata and doesn't re-apply filtering/inclusion logic when the metadata hash is mutated. Instead, we use a new explicit `define_derived_metadata` API. Fixes #825 and closes #829.
Fully supporting metadata mutation is fraught with difficulties see (rspec/rspec-rails#829 and the attempted fix in #1089). For RSpec 3, we decided to expose `define_derived_metadata` as an officially supported way to accomplish the sorts of things metadata mutation was used for in RSpec 2. This spec got left behind (since it was passing at the time, it wasn't noticed) but isn’t something we want to support going forward since module inclusion shouldn't mutate metadata. It’s also getting in the way of a perf optimization I'm implementing.
Fully supporting metadata mutation is fraught with difficulties see (rspec/rspec-rails#829 and the attempted fix in #1089). For RSpec 3, we decided to expose `define_derived_metadata` as an officially supported way to accomplish the sorts of things metadata mutation was used for in RSpec 2. This spec got left behind (since it was passing at the time, it wasn't noticed) but isn’t something we want to support going forward since module inclusion shouldn't mutate metadata. It’s also getting in the way of a perf optimization I'm implementing.
Fully supporting metadata mutation is fraught with difficulties see (rspec/rspec-rails#829 and the attempted fix in #1089). For RSpec 3, we decided to expose `define_derived_metadata` as an officially supported way to accomplish the sorts of things metadata mutation was used for in RSpec 2. This spec got left behind (since it was passing at the time, it wasn't noticed) but isn’t something we want to support going forward since module inclusion shouldn't mutate metadata. It’s also getting in the way of a perf optimization I'm implementing.
Fully supporting metadata mutation is fraught with difficulties see (rspec/rspec-rails#829 and the attempted fix in rspec#1089). For RSpec 3, we decided to expose `define_derived_metadata` as an officially supported way to accomplish the sorts of things metadata mutation was used for in RSpec 2. This spec got left behind (since it was passing at the time, it wasn't noticed) but isn’t something we want to support going forward since module inclusion shouldn't mutate metadata. It’s also getting in the way of a perf optimization I'm implementing.
We automagically configure ExampleGroup types for the various sets of Rails
helpers, however in 2.14 and master ATM these incorrectly pickup configured
helpers. E.g. a
before(:all, :type => :model)
will not run for a spec inspec/models
unless the type is set manually.This is because
rspec-core
configures hooks based on their current metadataand not on any metadata set later on. The alternative approach would be to
reload the global hooks from config when the metadata is changed in rspec-core
but this fixes #825 for now.
Note that manually specifying type is not affected, nor are any child groups
or examples. It is only the top level group that is affected.
Thoughts? /cc @alindeman @myronmarston