-
-
Notifications
You must be signed in to change notification settings - Fork 276
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
RSpec/RepeatedExample false positive #1932
Comments
After more investigation, I'm sorry but I do in fact have repeats. The failures highlight this:
287 and 290 are duplicates of each other, but the message didn't highlight this. Maybe a line number to say "duplicates this other line" ? |
Thanks for reporting! The key parts here are: example.implementation call, and how we get this implementation. Would you like to take a stab at this? |
So do you say that after fixing the duplicate all other offences are gone? That is weird, as eg there was an offence for line 296. I’d keep this open anyway yo at least add one multi-statement example, and an example where the same code is formatted differently (one-line is_expected.to vs same with newline). |
We have cops like this, and this will make a useful improvement. |
You cannot see the full describe block, but there truly were multiple instances, 8 to be exact: It { expect(subject).to be_urgent(T(“#{contingency_date}T12:00”)) }
It { expect(subject).to be_urgent(T(“#{contingency_date}T17:00”)) }
It { expect(subject).to be_urgent(T(“#{contingency_date}T12:00”)) }
It { expect(subject).to be_urgent(T(“#{contingency_date}T17:00”)) } In the example above, I have 2 @ 12, and 2 @ 17. The original code had a real oracle: 2024-06-25T12:00, and 2024-06-25T17:00, then 2024-06-26T12:00, and 2024-06-26T17:00. Notice that we had 2 dates: Jun 25 and Jun 26. When I switched over to string interpolation, I mistakenly used the same date & time for everything, and Rubocop CORRECTLY flagged the duplication. What I mistakenly understood was that the 1st 12:00 line was a duplicate of the 1st 17:00 line, but I forgot / misread the code and didn’t see the 2nd instance of 12:00. I would be happy to add the necessary code to report the “other” offending line. What if there are multiple instances? Should every line be reported, or only the 1st one? In our original example, we had 3 pairs of dates, at 12:00 and at 17:00. Should the 1st instance report that the 2nd one is a duplicate, or should all duplicates be found and reported as a block?
|
Understood, thank you!
I think we accumulate the other lines.
Yes. |
We had a spec file where we were asserting against an oracle. Then, we discovered issues with the values themselves, so we switched to string interpolation. Unfortunately, with the string interpolation, RSpec/RepeatedExample says there is an issue, when the values are actually different.
Expected behavior
Given the following code:
No Rubocop failures were expected. Note the string interpolation is different between the two lines.
In the trace below, these are lines 287 and 288.
Actual behavior
Steps to reproduce the problem
Of course, I can't reproduce this issue on a fresh file. In the original
RuboCop version
The text was updated successfully, but these errors were encountered: