RuboCop Minitest
repository·master·Indexed 41 days ago
https://github.com/rubocop/rubocop-minitestA RuboCop extension that enforces best practices and coding conventions for Minitest based on the community Minitest Style Guide. It includes specialized cops for test naming, assertion usage, and lifecycle hook ordering, as well as RuboCop::TestCase for testing custom cops.
What's inside RuboCop Minitest
- RuboCop Minitest is a RuboCop extension designed to enforce Minitest best practices and coding conventions. It is based on the community-driven Minitest style guide, helping developers maintain consistent and idiomatic Minitest codebases.
Understand RuboCop Minitest Cops
masterIn RuboCop terminology, 'cops' are individual checks performed on your code. Each cop is responsible for detecting a specific offense.
RuboCop Minitest contains a single department:
Minitest. These cops enforce Minitest best practices and coding conventions, many of which are derived from the Minitest Style Guide.Understand changes to test case detection
masterThe criteria for whatrubocop-minitestconsiders a test case has changed. A test case is now defined as apublicmethod that has no arguments and uses thetest_name prefix.Breaking Change: Minitest/AssertEmptyLiteral behavior update
masterIn version 0.11.0, theMinitest/AssertEmptyLiteralcop was updated to check forassert_equal([], array)instead ofassert([], array). This is a breaking change that may require updating existing test assertions to useassert_equalwith an empty array literal to satisfy the cop.Use the Minitest/LifecycleHooksOrder cop
masterTheMinitest/LifecycleHooksOrdercop is available to ensure that Minitest lifecycle hooks (such assetupandteardown) are defined in a consistent and expected order within your test files.Breaking Change: Automatic cop resolution in Minitest tests
masterIn version 0.40.0, the
inspect_sourceandinvestigatemethods in the Minitest test support no longer accept a cop argument. The cop under test is now resolved automatically based on the test class context.Additionally, the test configuration now automatically:
- Merges the default configuration for the cop under test.
- Sets
AllCops: TargetRubyVersionexplicitly.
Minitest/AssertTruthy unsafe autocorrection
masterIn version 0.26.0, theMinitest/AssertTruthycop has been marked as having unsafe autocorrection. When running RuboCop with autocorrect enabled, use caution with this cop as the automated changes may alter the intended logic of your tests.Support Active Support's `test` method in Minitest cops
masterAs of versionv0.13.0, theMinitest/MultipleAssertionsandMinitest/NoAssertionscops now support thetestmethod provided by Active Support. This allows these cops to correctly identify and lint assertion usage within Active Support-style test definitions.Use `it` block parameters in Minitest cops
masterAs of version 0.38.0,Minitestcops support inspecting theitblock parameter. This allows custom cops to access and validate the arguments passed to theitblock in Minitest tests.Upgrade requirements for RuboCop Minitest
masterStarting from version 0.11.0,rubocop-minitestrequires RuboCop 0.90 or higher to function.Install rubocop-minitest
masterYou can install the
rubocop-minitestgem directly via the command line or by adding it to yourGemfileif you are using Bundler. When using Bundler, userequire: falseto prevent the gem from being automatically loaded, as it is intended to be loaded by RuboCop during execution.$ gem install rubocop-minitestAdd rubocop-minitest to Gemfile
masterIf your project uses Bundler, add the following line to your
Gemfileto include the gem without requiring it immediately:gem 'rubocop-minitest', require: false