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

Better integration tests #31

Merged
merged 4 commits into from
Dec 18, 2023
Merged

Conversation

Earlopain
Copy link
Contributor

Part of what I wanted to do for #30 but this is pretty big already. Pulled it out so it doesn't get unreviewable.

This pulls in the test harness of rubocop-minitest. Tests are easier to read, more explicit in what's happening, more broad in their expectations, and also just faster.

The first commit hooks earlier into rubocop when irrelevant invalid offenses are removed, needed for test_non_code_offenses to work. Since the runner isn't involved anymore this test would otherwise fail. The test suites passes with this commit in isolation. InvestigationReport has been added in rubocop 0.87 rubocop/rubocop@f8813e7

Second commit is the rewrite. Since normally cops are tested one by one I needed to make some tweaks to the assertion module to make sense for this gem, where all cops are being run at once. I've isolated these changes to their own class. rubocop/rubocop-minitest#278 proposes to make the base assertions reusable by other gems, if that gets merged then this would be a drop in replacement.

I moved most of the tests to this new setup, but left those that clearly had something to do with some options being passed to rubocop, like the config test or the one with the cache. Most just asserted that offenses happened.

Test suite before: ~25.5 seconds
Test suite now: ~9.5 seconds

The runner is pretty high-level, if tests are running without involving the cli offenses aren't being rejected
This moves most tests to run inline instead of spawning an extra process.
This isn't only faster but also much more explicit in what is actually being tested against.
A few tests are left intact for issues that actually manifested during live rubocop runs.
Copy link
Collaborator

@palkan palkan left a comment

Choose a reason for hiding this comment

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

LGTM 👍

Let's fix the conflict and merge it

@Earlopain
Copy link
Contributor Author

Hm, there seems to be some incompatibility with how you apply autocorrect on early rubocop versions. Would you mind me bumping the minimum required version here already so I don't have to look into that only to remove it later anyways?

Just passing in the older auto_correct: true doesn't seem to cut it.

@palkan
Copy link
Collaborator

palkan commented Dec 18, 2023

Would you mind me bumping the minimum required version here already so I don't have to look into that only to remove it later anyways?

Yeah, I think we can do that given that 1.0.0 is more than 3 years old.

The new test harness has issues with older versions and it's planned to bump
to 1.45 anyways for its introduction of 3rd party templating support
@Earlopain
Copy link
Contributor Author

Yeah, I think we can do that given that 1.0.0 is more than 3 years old.

Great to hear, should be all good now!

@palkan palkan merged commit 0ca0d0d into rubocop:master Dec 18, 2023
12 checks passed
@Earlopain Earlopain deleted the better-integration-tests branch December 18, 2023 18:36
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.

2 participants