-
-
Notifications
You must be signed in to change notification settings - Fork 763
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
example_group is not longer supported #2232
Comments
I thought it was still supported. You're the first to report a problem with it. Can you provide an example of how it is not working for you? |
I didn't investigate much, tbh, but here's an issue I encountered. The following tests do not pass, unless one replaces the
|
Thanks for the example. When I run those, inclusion of |
It gets more interesting. Apparently this regressed between RSpec 3.1 and 3.2. The example passes in 3.0 and 3.1 and fails in 3.2. Digging in some more... |
It's looking like #1749 is at fault here, causing the regression. If I change the spec file to this: module Foo
def self.included(base)
puts "Included Foo in #{base.description}"
end
def foo
42
end
end
module Bar
def self.included(base)
puts "Included Bar in #{base.description}"
end
def foo
43
end
end
RSpec.configure do |config|
config.include Foo, example_group: { file_path: /./ } # One test fails
# config.include Foo, file_path: /./ # If this is used instead, tests pass
config.include Bar, bar: true
end
describe 'group: Foo', foo: true do
it "example: works" do
expect(foo).to eq 42
end
end
describe 'group: Bar', bar: true do
it "example: works" do
expect(foo).to eq 43
end
end Then run it, it produces this output:
Then if I swap the uncommented
In the first case, More investigation is needed but that's what I've found so far. |
I don't have a root cause yet, but I need to head to bed. |
This regressed in #1749. The changes there affected code like this: ``` ruby RSpec.configure do |c| c.include Mod, :example_group => { :file_path => /./ } end ``` In RSpec 2, and in RSpec 3 before #1749, this snippet would cause `Mod` to be included in every example group (since `/./` matches all file paths). After #1749, it would _not_ be included in any example groups. Instead, it was included in the singleton class of every example. In practice, this usually worked OK, as the methods from `Mod` were available to be called very every example, but it had subtle problems: * If the same method was defined in multiple included modules, the version of the method defined in a module included in this fashion would always get precedence due to the singleton class getting "first dibs" during method dispatch over the example group class. (This is the broken example given in #2232). * I believe this broke `c.extend Mod, :example_group => {...}` since we don't extend onto singleton classes. The reason is that the optimizations included in #1749 considered only metadata keys that the groups and examples have in their metadata hashes. In a group hash, `:example_group` is not a "real" metadata key--instead it is created lazily on first access using a `default_proc`. But example hashes still have it (it is a reference to the metadata of their group), so it allowed example filtering to work correctly, which in turn hid the bug. Fixes #2232.
This regressed in #1749. The changes there affected code like this: ``` ruby RSpec.configure do |c| c.include Mod, :example_group => { :file_path => /./ } end ``` In RSpec 2, and in RSpec 3 before #1749, this snippet would cause `Mod` to be included in every example group (since `/./` matches all file paths). After #1749, it would _not_ be included in any example groups. Instead, it was included in the singleton class of every example. In practice, this usually worked OK, as the methods from `Mod` were available to be called very every example, but it had subtle problems: * If the same method was defined in multiple included modules, the version of the method defined in a module included in this fashion would always get precedence due to the singleton class getting "first dibs" during method dispatch over the example group class. (This is the broken example given in #2232). * I believe this broke `c.extend Mod, :example_group => {...}` since we don't extend onto singleton classes. The reason is that the optimizations included in #1749 considered only metadata keys that the groups and examples have in their metadata hashes. In a group hash, `:example_group` is not a "real" metadata key--instead it is created lazily on first access using a `default_proc`. But example hashes still have it (it is a reference to the metadata of their group), so it allowed example filtering to work correctly, which in turn hid the bug. Fixes #2232.
@marcandre: I've got a fix for this in #2234. Want to give it a try? |
Thanks a lot for the fix! |
This regressed in rspec#1749. The changes there affected code like this: ``` ruby RSpec.configure do |c| c.include Mod, :example_group => { :file_path => /./ } end ``` In RSpec 2, and in RSpec 3 before rspec#1749, this snippet would cause `Mod` to be included in every example group (since `/./` matches all file paths). After rspec#1749, it would _not_ be included in any example groups. Instead, it was included in the singleton class of every example. In practice, this usually worked OK, as the methods from `Mod` were available to be called very every example, but it had subtle problems: * If the same method was defined in multiple included modules, the version of the method defined in a module included in this fashion would always get precedence due to the singleton class getting "first dibs" during method dispatch over the example group class. (This is the broken example given in rspec#2232). * I believe this broke `c.extend Mod, :example_group => {...}` since we don't extend onto singleton classes. The reason is that the optimizations included in rspec#1749 considered only metadata keys that the groups and examples have in their metadata hashes. In a group hash, `:example_group` is not a "real" metadata key--instead it is created lazily on first access using a `default_proc`. But example hashes still have it (it is a reference to the metadata of their group), so it allowed example filtering to work correctly, which in turn hid the bug. Fixes rspec#2232.
rspec currently states that "Filtering by an
:example_group
subhash is deprecated. Use the subhash to filter directly instead.". I took "deprecated" to mean that it still worked but wouldn't in a later version. It doesn't work.Could it please either be supported, or else the warning should be an error with a different wording.
The text was updated successfully, but these errors were encountered: