-
-
Notifications
You must be signed in to change notification settings - Fork 753
Conversation
This needs a 2.99 deprecation for the case where it is changing. I'll work on that in a bit. |
It used to return the outermost described class. It doesn't happen very often that there is more than one class being described in the set of nested example groups (and we generally recommend against it), but this was surprising behavior to me. Fixes #1114.
@@ -150,7 +150,7 @@ def described_class | |||
end | |||
end | |||
|
|||
container_stack.reverse.each do |g| | |||
container_stack.each do |g| |
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.
Why? (Just curious)
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.
Wait... Is this all that's needed to make the describes reference the innermost class?
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.
Yep. This searches for a described class from the inner most group to the outermost group, rather than the reverse like before.
That said, I think I just realized a possible bug with this, related to the container_stack.each
loop above this -- let me play a bit and see if the bug I'm thinking of exists.
In the last commit, I made inner `describe SomeClass` example groups get `SomeClass` as the described_class. The logic confusingly allowed a `:described_class` metadata key in an outer group take precedence, which meant that the behavior depended on whether or not `described_class` was referenced from the outer group. This fixes that, making it work consistently: - Use `:described_class` is present. - Otherwise, use the group's `describe` arg (unless it's something like a string). - If neither of those, look in the parent and recurse.
I was right about there being a bug. Fix pushed. Want to re-review, @JonRowe? |
LGTM |
Thanks for reviewing. Going to hold off merging until I have a 2.99 deprecation PR ready. |
Fix nested described class
Fixes rspec#2627 Documentation for `described_class` was out of date, a change was made in early 3.0 in rspec#1361, but was not reflected to the docs. Also, documentation for implicit `subject` was off, even though there is a feature describing how it behaves.
Fixes rspec#2627 Documentation for `described_class` was out of date, a change was made in early 3.0 in rspec#1361, but was not reflected to the docs. Also, documentation for implicit `subject` was off, even though there is a feature describing how it behaves.
Fixes rspec/rspec-core#2627 Documentation for `described_class` was out of date, a change was made in early 3.0 in rspec/rspec-core#1361, but was not reflected to the docs. Also, documentation for implicit `subject` was off, even though there is a feature describing how it behaves. --- This commit was imported from rspec/rspec-core@e90f9b5.
Fixes rspec/rspec-core#2627 Documentation for `described_class` was out of date, a change was made in early 3.0 in rspec/rspec-core#1361, but was not reflected to the docs. Also, documentation for implicit `subject` was off, even though there is a feature describing how it behaves. --- This commit was imported from rspec/rspec-core@861986d.
Make
described_class
to return innermost described class.It used to return the outermost described class. It doesn't
happen very often that there is more than one class being
described in the set of nested example groups (and we
generally recommend against it), but this was surprising behavior
to me.
Fixes #1114.