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

expect_correction with loop #8062

Merged
merged 4 commits into from
Jun 1, 2020

Conversation

bquorning
Copy link
Contributor

@bquorning bquorning commented May 29, 2020

In some places, we spec what happens after one auto-correct iteration, and in some places we spec what happens after many auto-correct iterations.

As mentioned in #8003, there is no longer any reason to use helpers like autocorrect_source_with_loop. This PR removes that method and all our uses of it.


Before submitting the PR make sure the following are checked:

  • Wrote good commit messages.
  • Commit message starts with [Fix #issue-number] (if the related issue exists).
  • Feature branch is up-to-date with master (if not - rebase it).
  • Squashed related commits together.
  • Added tests.
  • Added an entry to the Changelog if the new code introduces user-observable changes. See changelog entry format.
  • The PR relates to only one subject with a clear title and description in grammatically correct, complete sentences.
  • Run bundle exec rake default. It executes all tests and RuboCop for itself, and generates the documentation.

end

# Prepare for next loop
cop.instance_variable_set(:@corrections, [])
Copy link
Contributor Author

@bquorning bquorning May 29, 2020

Choose a reason for hiding this comment

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

This bit is ugly! Is there another way to accomplish the same thing?

Copy link
Contributor

Choose a reason for hiding this comment

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

It also won't work after #7868 lands...

@bquorning bquorning force-pushed the expect-correction-with-loop branch from d1f3649 to bdbc534 Compare May 29, 2020 15:20
@bquorning bquorning requested a review from Darhazer May 29, 2020 15:22
@bquorning bquorning marked this pull request as ready for review May 29, 2020 15:22
@bquorning bquorning requested a review from marcandre May 29, 2020 15:22
In some places, we spec what happens after one auto-correct iteration
and what happens after _many_ auto-correct iterations.
@bquorning bquorning force-pushed the expect-correction-with-loop branch from bdbc534 to 856e421 Compare May 29, 2020 15:26
@bquorning
Copy link
Contributor Author

@pirj Maybe you want to take a look at this PR?

@marcandre
Copy link
Contributor

API-wise, I like that it's very convenient; I wonder if it would it better to also spec the intermediate steps?

E.g.

expect_offense(<<~RUBY)
  # ... code with offense
RUBY
expect_correction_offense(<<~RUBY)
  # ... corrected code with offense
RUBY
expect_correction(<<~RUBY)
  # ... final corrected code without offense
RUBY

One advantage I see is that it makes it clear how the final correction is had. Also it specs what happens if someone entered the intermediate code for some reason. Maybe that's too strict or verbose though?

Copy link
Member

@pirj pirj left a comment

Choose a reason for hiding this comment

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

Don't see any flaws 👍


def expect_correction(correction)
def expect_correction(correction, loop: false)
Copy link
Member

Choose a reason for hiding this comment

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

What are the implications of always using loop: true?

Copy link
Member

Choose a reason for hiding this comment

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

rspec execution time didn't change with loop: true (I've actually removed this parameter and removed loop: true around the code.

I've faced an RuboCop::Runner::InfiniteCorrectionLoop and some other spec failures. Is this due to disagreeing cops?

@bbatsov bbatsov merged commit 510f3f7 into rubocop:master Jun 1, 2020
@marcandre
Copy link
Contributor

I still feel this raises questions:

  • should we be more specific with spec'ing the intermediate steps?
  • or should we spec that a step leads to the expected correction (as @pirj suggests)?
  • or should we not always test only the final step?
  • why are there infinite loop corrections in our test base?

@bbatsov
Copy link
Collaborator

bbatsov commented Jun 1, 2020

I think it's best to discuss them in a dedicated ticket. This PR improves the status quo, which is why I decided to merge it, but I agree that there's plenty of room for improvement.

@marcandre
Copy link
Contributor

This PR improves the status quo

No doubt about that :-)

I opened #8075 and #8076

@bquorning bquorning deleted the expect-correction-with-loop branch June 1, 2020 17:58
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

4 participants