Skip to content
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

Fix a regression in our metadata backwards compatibility #1490

Merged
merged 2 commits into from Apr 18, 2014

Conversation

myronmarston
Copy link
Member

Fix metadata backwards compat to handle deep nesting.

This is a bit confusing, but the behavior in 2.x was:

* a group's `metadata` did not have it's computed
  keys directly available; they were exposed off of
  the `:example_group` subhash.
* The `:example_group` subhash had a `:example_group`
  key that exposed the parent group's metadata
  (both user metadata and computed keys).

Before this, we were inserting extra `:example_group`
subhashes between the layers.

@myronmarston myronmarston added this to the 3.0 milestone Apr 17, 2014
@myronmarston myronmarston self-assigned this Apr 17, 2014
This is a bit confusing, but the behavior in 2.x was:

* a group's `metadata` did not have it's computed
  keys directly available; they were exposed off of
  the `:example_group` subhash.
* The `:example_group` subhash had a `:example_group`
  key that exposed the parent group's metadata
  (both user metadata and computed keys).

Before this, we were inserting extra `:example_group`
subhashes between the layers.
@myronmarston myronmarston changed the title Add a spec documenting a regression in our metadata backwards compatibility Fix a regression in our metadata backwards compatibility Apr 17, 2014
@myronmarston
Copy link
Member Author

/cc @JonRowe

@JonRowe
Copy link
Member

JonRowe commented Apr 18, 2014

Oops, LGTM, merge when green.

@myronmarston
Copy link
Member Author

Actually, I found a case that still has a bug...digging in now.

@@ -460,13 +460,29 @@ def value_for(*args)
describe("nested") { child = metadata }
end

expect(child[:example_group][:example_group]).to include(
expect(child[:example_group][:example_group].to_h).to include(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Out of curiosity, is this not a hash already?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope. It's a LegacyExampleGroupHash instance.

In RSpec 2.x, an example's `metadata[:example_group]`
did not returned it's example group's `metadata`,
but rather it's example group's `metadata[:example_group]`,
which is where all the computed values for the example
group went.

In RSpec 3, we've simplified this nesting structure
(it's silly to put an example group's computed
properties on a nested subhash keyed by `:example_group`),
but our backwards compatibility didn't work properly with this.

The problem was that `example.metadata[:example_group][:example_group]`
returned the `LegacyExampleGroupHash` available off of
`example.example_group.metadata[:example_group]`, which contains
the computed properties of the example group, but on 2.99 this
returned the computed properties of the parent group of the example's
group.

Unfortunately, I had to make one spec pending as I can't find
a way to keep it passing with the difference in how the
metadata is exposed from an example vs a group, but it really
only matters when people mutate the metadata hash and that's
not a normal, supported use case.  I think the backwards compatibility
is more important right now.  We may revert this at some point
after 3.0's been out for awhile and people have had time to
adjust to the deprecation warnings issued for the metadata changes.
@myronmarston
Copy link
Member Author

OK @JonRowe, I pushed my further fix. See the massive commit message on 9ffcc38 for the full story.

@JonRowe
Copy link
Member

JonRowe commented Apr 18, 2014

So, one major use case where metadata is mutated is rspec-rails. What happens in that situation?

@myronmarston
Copy link
Member Author

Well, I thought our plan was to provide an official API to meet rspec-rails' needs so that it wouldn't have to mutate anymore?

Anyhow, the change here only affects mutation when it's done to the example group metadata after examples in that group have been defined. I think rspec-rails' mutation is done before examples are defined in the group?

@JonRowe
Copy link
Member

JonRowe commented Apr 18, 2014

That's the plan, but we're not there yet, I think rspec-rails mutation is done after the examples are defined, because it's inferring there type after loading them based on the file structure?

@JonRowe
Copy link
Member

JonRowe commented Apr 18, 2014

Anyway you understand this better than me so it gets my sign off.

@myronmarston
Copy link
Member Author

That's the plan, but we're not there yet, I think rspec-rails mutation is done after the examples are defined, because it's inferring there type after loading them based on the file structure?

Nope, mutation like this happens before any examples are defined (I just ran some tests to confirm it). There is, however, this mutation that could happen after examples are defined:

https://github.com/rspec/rspec-rails/blob/3d63b16bc6d8f8cf6d605e1d62e940f8441d0cd7/lib/rspec/rails/example/controller_example_group.rb#L63

But the rspec-rails build appears to be green with this change. Also, mutation isn't necessarily a problem; it just means that example.metadata[:example_group] may have different hash entries than example.example_group.metadata since they no longer return the same hash instance.

myronmarston added a commit that referenced this pull request Apr 18, 2014
Fix a regression in our metadata backwards compatibility
@myronmarston myronmarston merged commit b691a41 into master Apr 18, 2014
@myronmarston myronmarston deleted the metadata-regression branch April 18, 2014 06:33
@pirj pirj mentioned this pull request Nov 23, 2020
4 tasks
pirj added a commit that referenced this pull request Feb 10, 2021
pirj added a commit that referenced this pull request Feb 10, 2021
pirj added a commit that referenced this pull request Feb 10, 2021
pirj added a commit that referenced this pull request Feb 10, 2021
yujinakayama pushed a commit to yujinakayama/rspec-monorepo that referenced this pull request Oct 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants