-
-
Notifications
You must be signed in to change notification settings - Fork 277
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
Finish branch coverage for RSpec/DescribedClass
#2030
Finish branch coverage for RSpec/DescribedClass
#2030
Conversation
|
29bd635
to
a64bebc
Compare
Thanks @bquorning -- it works with a little magic sprinkled in, and it documents the behavior I think. |
It's possible there's another approach here to handle the |
it 'ignores a class with a dynamic namespace' do | ||
expect_no_offenses(<<~RUBY) | ||
describe MyClass do | ||
subject { (("MyClass" + "3").constantize)::MyClass } |
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.
This example still seems a bit far fetched 😅
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.
I’ll see in real-world-rspec if there’s any code that hits the branch you’re looking at.
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.
Not just far fetched, a little hard to find! A good puzzle.
I buried this in the updated description above, but the way we're getting past the case statement here is just by having a :begin
node from the parentheses.
I replaced the example with a simpler parenthesized method call.
The weird thing is:
subject { method_that_returns_a_class::MyClass }
does get handled.
I'm not certain how method_that_returns_a_class
or (method_that_returns_a_class)
ought to be corrected, but maybe they should be handled identically.
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.
subject { method_that_returns_a_class::MyClass }
makes namespace
a send type, whereas subject { (method_that_returns_a_class)::MyClass }
makes namespace
a begin type. So maybe the test case we want is just explicitly having parentheses around the namespace?
a64bebc
to
8cfcd26
Compare
Btw I just found that changing line 85 from |
8cfcd26
to
67ecc8f
Compare
Great find! Separate issue, but another perk of the exercise. |
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.
Don’t forget to update .simplecov ✨
I didn’t want to start a conflict cascade. I think we can change it to 100%
when all of your PRs are merged?
…On Sun, Feb 9, 2025 at 10:18 AM Benjamin Quorning ***@***.***> wrote:
***@***.**** commented on this pull request.
Don’t forget to update .simplecov ✨
—
Reply to this email directly, view it on GitHub
<#2030 (review)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AANFDS5YWNIM4WLWMJO4XV32O6LXFAVCNFSM6AAAAABWYJTDI2VHI2DSMVQWIX3LMV43YUDVNRWFEZLROVSXG5CSMV3GSZLXHMZDMMBUGMZDQNZTGI>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
Finish branch coverage for
RSpec/DescribedClass
Showing that the tested code evaluates:
Although at this point the math is superfluous --
(method_that_returns_a_class)::MyClass
will cover this branch whilemethod_that_returns_a_class::MyClass
will notBefore:
![Screenshot 2025-02-08 at 10 25 14 PM](https://private-user-images.githubusercontent.com/1724875/411291503-25c1f242-5f33-4a60-8d66-f0df3ad85b0f.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzk1MzAyMDMsIm5iZiI6MTczOTUyOTkwMywicGF0aCI6Ii8xNzI0ODc1LzQxMTI5MTUwMy0yNWMxZjI0Mi01ZjMzLTRhNjAtOGQ2Ni1mMGRmM2FkODViMGYucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI1MDIxNCUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNTAyMTRUMTA0NTAzWiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9ZmJmMzEzMzE2ZWVlYTU3YjU5NTdjN2YxNGU4OGYzZWI5NDYyODgwNzRjZWEzNjU4NDFjYTdiMTJiMGI5N2JlOCZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QifQ.IJeGXhhbUupg73evMmK3ZrhlZPjvQROUGwPhP2W2MLE)
![Screenshot 2025-02-08 at 10 25 31 PM](https://private-user-images.githubusercontent.com/1724875/411291517-8a83e35e-1cb5-4e5c-9701-a73c49e4a817.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzk1MzAyMDMsIm5iZiI6MTczOTUyOTkwMywicGF0aCI6Ii8xNzI0ODc1LzQxMTI5MTUxNy04YTgzZTM1ZS0xY2I1LTRlNWMtOTcwMS1hNzNjNDllNGE4MTcucG5nP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI1MDIxNCUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNTAyMTRUMTA0NTAzWiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9ZWYwZDEyY2Y3NzBmMzViMDU3MjZkMDVkY2RhNTdhNWE3OWM1MmI3MmQwODQwMzQzZGVkNmYxMGRhNGUzMGJhNCZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QifQ.401nrDy25MpaFYwA_jgOk5bnj1FCEYdqTjBmbQwGcfM)
After:
Before submitting the PR make sure the following are checked:
master
(if not - rebase it).CHANGELOG.md
if the new code introduces user-observable changes.bundle exec rake
) passes (be sure to run this locally, since it may produce updated documentation that you will need to commit).If you have created a new cop:
config/default.yml
.Enabled: pending
inconfig/default.yml
.Enabled: true
in.rubocop.yml
.VersionAdded: "<<next>>"
indefault/config.yml
.If you have modified an existing cop's configuration options:
VersionChanged: "<<next>>"
inconfig/default.yml
.