rubocop / rubocop-md

RuboCop for Markdown code snippets
MIT License
71 stars 14 forks source link

Better integration tests #31

Closed Earlopain closed 8 months ago

Earlopain commented 9 months ago

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 https://github.com/rubocop/rubocop/commit/f8813e76cef5c06cfe1f3a73b032f4f06de7de6c

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. https://github.com/rubocop/rubocop-minitest/pull/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

Earlopain commented 8 months ago

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 commented 8 months ago

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.

Earlopain commented 8 months ago

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!