rubocop-minitest
rubocop-minitest copied to clipboard
Make the RuboCop::Minitest::Test suite re-usable by gem consumers
I've been writing custom cops for various jobs for a while now, but I've never had a consistent way to write tests for products that use minitest as the test suite (officially Rubocop only provides rspec
helpers) , I started to look around to see what this Gem did and figured it would make sense to make rubocop-minitest
provide a minitest class for others that write custom cops for their own code bases.
This does a couple of things
- Makes a new
Rubocop::Minitest::Test
class that includes the code fromassert_offense
(I don't feel like it needs to be a module), and it also uses declarative testing for people to use. - I moved the "real" test suites in this gem to use the new base class, and kept the code blocks being tested as
Minitest::Test
- I added declarative testing since all the test suites I've been in have it, where instead of using
def test_something_does_something...end
you can dotest "something does something" do...end
which makes it easier to read test names.
I tested this locally in an app of mine and it works great! So it can allow a consistent way for people to write custom cops and easily test them!
Before submitting the PR make sure the following are checked:
- [x] The PR relates to only one subject with a clear title and description in grammatically correct, complete sentences.
- [x] Wrote good commit messages.
- [-] Commit message starts with
[Fix #issue-number]
(if the related issue exists). - [x] Feature branch is up-to-date with
master
(if not - rebase it). - [x] Squashed related commits together.
- [x] Added tests.
- [x] Ran
bundle exec rake default
. It executes all tests and runs RuboCop on its own code. - [x] Added an entry (file) to the changelog folder named
{change_type}_{change_description}.md
if the new code introduces user-observable changes. See changelog entry format for details.
This makes a lot of sense to me and I'd love to use it.
If this is being exposed like this then I think it needs some documetation on how to pass global and cop specific config to a test.
See https://github.com/rubocop/rubocop-minitest/blob/b446022ea09b3f5558df9c0106c9e714c6fc1ec5/test/rubocop/cop/minitest/global_expectations_test.rb#L504-L513 and https://github.com/rubocop/rubocop-minitest/blob/b446022ea09b3f5558df9c0106c9e714c6fc1ec5/test/rubocop/cop/minitest/multiple_assertions_test.rb#L339-L343
@Earlopain Updated the casing of RuboCop
, updated the sample docs (both inline and README.md
), handling the nil case for @cop
Squashed commits and confirmed CI is passing locally
@koic 👋 Could I ask for a review?